from machine import Pin import bluetooth from ble_simple_peripheral import BLESimplePeripheral ble = bluetooth.BLE() sp = BLESimplePeripheral(ble) LED0 = Pin("LED", Pin.OUT) LED1 = Pin(16, Pin.OUT) LED2 = Pin(17, Pin.OUT) Beeper = Pin(13, Pin.OUT) def on_rx(data): print("Data received: ", data) if data == b'LED0\r\n': LED0.toggle() if data == b'LED1\r\n': LED1.toggle() if data == b'LED2\r\n': LED2.toggle() if data == b'Beep\r\n': Beeper.toggle() while(1): if sp.is_connected(): sp.on_write(on_rx)