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: r = int(data[1:4]) g = int(data[5:8]) b = int(data[9:12]) print('red = ',r,' green = ',g,' blue = ',b) np.fill([r,g,b]) np.write() flag = 1 except: print('format for data is RxxxGxxxBxxx') 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 v2', White, Black) flag = 1 while(1): if sp.is_connected(): sp.on_write(on_rx) if(flag): LCD.Text2(str(r) + ' ', 300, 50, Yellow, Black) LCD.Text2(str(g) + ' ', 300, 100, Yellow, Black) LCD.Text2(str(b) + ' ', 300, 150, Yellow, Black) flag = 0