BLE 雙向測試 V7RC 傳出的訊號可快速顯示在螢幕上
而 Pico_Game 按鈕按下後,也可回傳訊息至手機端顯示,雙向測試成功
V7RC 回傳的格式 MSGxxxxxx#
import st7789
import tft_config
import ble_uart_v7rc
import bluetooth
import ble_advertising
import math
tft = tft_config.config(1)
CH1 = None
CH2 = None
button_a = machine.Pin(2,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
button_b = machine.Pin(14,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
button_up = machine.Pin(8,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
button_down = machine.Pin(7,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
button_left = machine.Pin(15,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
button_right = machine.Pin(9,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
button_menu = machine.Pin(1,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
button_start = machine.Pin(0,machine.Pin.IN, machine.Pin.PULL_UP) #Internal pull-up
def color_hex(c):
if type(c) is str:
c = int(c[1:], 16)
r = (c >> 16) & 0xFF
g = (c >> 8) & 0xFF
b = c & 0xFF
return st7789.color565(r, g, b)
def rx_callback():
ble_data = uart.read().decode().strip()
CH1 = int(((ble_data)[3:7]),10)
CH2 = int(((ble_data)[7:11]),10)
import vga1_16x16 as vga1_16x16
tft.text(vga1_16x16,str((ble_data)), 0, 60, color_hex('#ffffff'))
print(CH1)
tft.init()
tft.fill(color_hex('#000000'))
CH1 = 1500
CH2 = 1500
ble = bluetooth.BLE(); uart=ble_uart_v7rc.ble_uart(ble, rx_callback=rx_callback, name="pico_car")
while True:
if button_a.value()==0:
uart.write("MSGPico_Game test#")
if button_b.value()==0:
uart.write("MSGHello,I am Mason#")
if button_up.value()==0:
uart.write("MSGUP_button#")
if button_down.value()==0:
uart.write("MSGDOWN_button#")
if button_left.value()==0:
uart.write("MSGLEFT_button#")
if button_right.value()==0:
uart.write("MSGRIGHT_button#")
if button_menu.value()==0:
uart.write("MSGMENU_button#")
if button_start.value()==0:
uart.write("MSGStart_button#")