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 Level, flag print("Data received: ", data) try: Level = int(data[0:3]) Level = min(Level, 255) np.fill([Level,Level,Level]) np.write() flag = 1 except: print('invalid data entry') 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('Brightness: ', 50, 50, Yellow, Black) LCD.Title('Flashlight v1', White, Black) flag = 1 while(1): if sp.is_connected(): sp.on_write(on_rx) if(flag): print('Brightness = ',Level) LCD.Text2(str(Level) + ' ', 300, 50, Yellow, Black) flag = 0