def event_handler(id, handle, data): global rtc global periph global serv_env_sense global notif_enabled if id == constants.EVT_GAP_CONNECTED: # indicated 'connected' LED(1).on() elif id == constants.EVT_GAP_DISCONNECTED: # stop low power timer rtc.stop() # indicate 'disconnected' LED(1).off() # restart advertisment periph.advertise(device_name="micr_temp", services=[serv_env_sense]) elif id == constants.EVT_GATTS_WRITE: # write to this Characteristic is to CCCD if int(data[0]) == 1: notif_enabled = True # start low power timer rtc.start() else: notif_enabled = False # stop low power timer rtc.stop()
def event_handler(id, handle, data): global periph global service if id == constants.EVT_GAP_CONNECTED: pass elif id == constants.EVT_GAP_DISCONNECTED: # restart advertisment periph.advertise(device_name="Nano Blinky", services=[service]) elif id == constants.EVT_GATTS_WRITE: LED(1).on() if int(data[0]) else LED(1).off()
def rtcint(timer_id): LED(1).on() i2c.writeto(57,bytearray([command,ctl_poweron])) sleep_ms(500) i2c.writeto(57,bytearray([command|0x20|0x0e])) i2c.readfrom_into(57,ch1) i2c.writeto(57,bytearray([command|0x20|0x0c])) i2c.readfrom_into(57,ch0) i2c.writeto(57,bytearray([command,ctl_poweroff])) tot = int.from_bytes(ch0,'little') ir = int.from_bytes(ch1,'little') print ('Total',tot) print ('IR: ',ir) LED(1).off()
def event_handler(id, handle, data): global periph, service, notif_enabled if id == constants.EVT_GAP_CONNECTED: # indicated 'connected' LED(1).on() elif id == constants.EVT_GAP_DISCONNECTED: # indicate 'disconnected' LED(1).off() # restart advertisment periph.advertise(device_name="Temperature Sensor", services=[service]) elif id == constants.EVT_GATTS_WRITE: # write to this Characteristic is to CCCD if int(data[0]) == 1: notif_enabled = True else: notif_enabled = False
def toggle_led(timer_id): LED(4).toggle()
# Blinky example import time from board import LED led_red = LED(1) led_green = LED(2) led_blue = LED(3) led_yellow = LED(4) while (True): led_blue.on() time.sleep_ms(250) led_blue.off() led_red.on() time.sleep_ms(250) led_red.off() led_green.on() time.sleep_ms(250) led_green.off() led_yellow.on() time.sleep_ms(250) led_yellow.off() time.sleep_ms(500)
def event_handler(id, handle, data): global periph global service if id == constants.EVT_GAP_CONNECTED: pass elif id == constants.EVT_GAP_DISCONNECTED: # restart advertisment periph.advertise(device_name="Nano Blinky", services=[service]) elif id == constants.EVT_GATTS_WRITE: LED(1).on() if int(data[0]) else LED(1).off() # start off with LED(1) off LED(1).off() notif_enabled = False uuid_service = UUID("0x1523") uuid_led = UUID("0x1525") service = Service(uuid_service) char_led = Characteristic(uuid_led, props=Characteristic.PROP_WRITE) service.addCharacteristic(char_led) periph = Peripheral() periph.addService(service) periph.setConnectionHandler(event_handler) periph.advertise(device_name="Nano Blinky", services=[service]) while (True):
# Blinky example import time from board import LED LED_RED=1 LED_GREEN=2 LED_BLUE=3 LED_YELLOW=4 while (True): LED(LED_BLUE).on() time.sleep_ms(150) LED(LED_BLUE).off() time.sleep_ms(100) LED(LED_BLUE).on() time.sleep_ms(150) LED(LED_BLUE).off() time.sleep_ms(600)