from machine import Pin, Timer 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) Ton = 1 Toff = 99 Status = 0 tim = Timer() def Light_On(timer): global Ton, Status np.fill([255,255,255]) np.write() tim.init(period = Ton, mode=Timer.ONE_SHOT, callback=Light_Off) def Light_Off(timer): global Toff, Status np.fill([0,0,0]) np.write() if(Status): tim.init(period = Toff, mode=Timer.ONE_SHOT, callback=Light_On) def on_rx(data): global Ton, Toff, Status, flag print("Data received: ", data) try: cmd = chr(data[0]) if(cmd == 'N'): Ton = int(data[1:4]) if(cmd == 'F'): Toff = int(data[1:4]) if(cmd == 'G'): Status = 1 tim.init(period = Ton, mode=Timer.ONE_SHOT, callback=Light_On) if(cmd == 'S'): Status = 0 flag = 1 except: print('invalid data entry') print('Nxxx set the on time in ms') print('Fxxx set the off time in ms') print('G start the strobe light') print('S stop the strobe light') 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('T(on): ', 50, 50, Yellow, Black) LCD.Text2('T(off): ', 50, 100, Yellow, Black) LCD.Text2('Status: ', 50, 150, Yellow, Black) LCD.Title('Strobe Light', White, Black) np.fill([0,0,0]) np.write() flag = 1 while(1): if sp.is_connected(): sp.on_write(on_rx) if(flag): LCD.Number2(Ton, 3, 0, 300, 50, Yellow, Black) LCD.Number2(Toff, 3, 0, 300, 100, Yellow, Black) if(Status == 1): LCD.Text2('On ', 300, 150, Yellow, Black) else: LCD.Text2('Off', 300, 150, Yellow, Black) flag = 0