from machine import Pin import bluetooth from ble_simple_peripheral import BLESimplePeripheral import neopixel import LCD ble = bluetooth.BLE() sp = BLESimplePeripheral(ble) N = 16 p = machine.Pin(1) np = neopixel.NeoPixel(p, N, bpp=3, timing=1) def on_rx(data): global r,g,b,flag print("Data received: ", data) try: cmd = chr(data[0]) if(cmd == 'R'): r = int(data[1:4]) if(cmd == 'G'): g = int(data[1:4]) if(cmd == 'B'): b = int(data[1:4]) print('b = ', b) if(cmd == 'C'): r = g = b = 0 if(cmd == 'W'): np.fill([r,g,b]) np.write() flag = 1 except: print ('data format is Rxxx / Gxxx / Bxxx / C / W ') LCD.Init() White = LCD.RGB(250,250,250) Black = LCD.RGB(0,0,0) Yellow = LCD.RGB(250,250,0) LCD.Clear(Black) LCD.Box(1,1,479,319,White) LCD.Text2('Red: ', 50, 50, Yellow, Black) LCD.Text2('Green: ', 50, 100, Yellow, Black) LCD.Text2('Blue: ', 50, 150, Yellow, Black) LCD.Title('Flashlight v3', White, Black) flag = 1 r=g=b=0 np.fill([r,g,b]) np.write() while(1): if sp.is_connected(): sp.on_write(on_rx) if(flag): LCD.Number2(r, 3, 0, 300, 50, Yellow, Black) LCD.Number2(g, 3, 0, 300, 100, Yellow, Black) LCD.Number2(b, 3, 0, 300, 150, Yellow, Black) flag = 0