diff --git a/demos/ble-ws2812-card10.py b/demos/ble-ws2812-card10.py new file mode 100644 index 0000000000000000000000000000000000000000..6216ea3bf85d65aea3e2c950aa004cdf0e166f32 --- /dev/null +++ b/demos/ble-ws2812-card10.py @@ -0,0 +1,35 @@ +import ws2812, gpio, bluetooth, time, display +from micropython import const + +_IRQ_GATTS_WRITE = const(3) + +WS2812_SERVICE_UUID = \ + bluetooth.UUID("23230300-2342-2342-2342-234223422342") +SET_ALL = ( + bluetooth.UUID("23230301-2342-2342-2342-234223422342"), + bluetooth.FLAG_WRITE +) +WS2812_SERVICE = ( + WS2812_SERVICE_UUID, + (SET_ALL,) +) + +def irq(event, data): + if event == _IRQ_GATTS_WRITE: + conn_handle, value_handle = data + value = ble.gatts_read(value_handle) + ws2812.set_all(gpio.WRISTBAND_3, [value] * 3) + +if __name__ == "__main__": + display.open().backlight(0) + gpio.set_mode(gpio.WRISTBAND_3, gpio.mode.OUTPUT) + + ble = bluetooth.BLE() + ble.active(True) + ble.irq(irq) + ble.gatts_register_services((WS2812_SERVICE,)) + + print("Waiting for connection!") + + while True: + time.sleep(1) diff --git a/demos/ble-ws2812-host.py b/demos/ble-ws2812-host.py new file mode 100644 index 0000000000000000000000000000000000000000..b00ee7c842bf6bc6a6a8c843508db6b067128e5e --- /dev/null +++ b/demos/ble-ws2812-host.py @@ -0,0 +1,17 @@ +#!/usr/bin/env python3 +import bluepy +import time +import colorsys + +p = bluepy.btle.Peripheral("CA:4D:10:01:ff:64") +c = p.getCharacteristics( + uuid='23230301-2342-2342-2342-234223422342')[0] + +hue = 0 +while 1: + r,g,b = colorsys.hsv_to_rgb(hue, 1, 0.1) + c.write(b"%c%c%c" % + (int(r*255), int(g*255), int(b*255)), True) + time.sleep(.1) + hue += 0.1 +