from machine import LED total_pin = 4 pin_num=1 while pin_num < (total_pin+1): led_test=LED(int(pin_num)) #LED1~4循序亮灭 print(led_test) led_test.on() for j in range(0,5000,1): continue led_test.off() for j in range(0,5000,1): continue led_test.toggle() for j in range(0,5000,1): continue led_test.toggle() for j in range(0,5000,1): continue pin_num=pin_num+1
ledy = LED('ledy') ledr = LED('ledr') #確保 BLE 回到 CMD mode ble.write('!CCMD@') delay(150) ble.write('!CCMD@') delay(150) # enable BLE System MSG ble.write('AT+EN_SYSMSG=1\r\n') delay(50) while True: msg = ble.readline() print (msg) recv_data = str(msg,'utf-8') # 200ms will return a data print (recv_data) if recv_data == 'A' : ledy.toggle() if recv_data == 'B' : ledr.toggle() if recv_data == 'b' : ledr.toggle()
ledy.off() ledr.off() ledg.off() keya = Switch('keya') #使用 UART1 連接 BLE,並增加接收 Buffer BLE_uart = UART(1, 115200, read_buf_len=1024) # 確認切到 command mode BLE_uart.write('!CCMD@') utime.sleep_ms(200) BLE_uart.write('!CCMD@') utime.sleep_ms(200) ledy.toggle() # 改變 BLE mode to PERIPHERAL mode (client ) BLE_uart.write('AT+ROLE=?\r\n') utime.sleep_ms(20) Resp = BLE_uart.readline() if 'PERIPHERAL' in Resp: BLE_uart.write('AT+ROLE=C\r\n') utime.sleep_ms(500) while True: input_data = BLE_uart.readline() if 'READY OK' in input_data: break ledy.toggle()
from machine import LED, delay ledR = LED('ledr') ledY = LED('ledy') ledG = LED('ledg') ledR.off() ledY.off() ledG.off() delay(1000) ledR.on() ledY.on() ledG.on() while True: ledG.toggle() delay(1000)