From 2876d7a9ec90cd75274b18f6383fa35bd075d6b2 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 3 Aug 2021 18:18:49 +0200 Subject: initial commit --- main.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 main.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..56ec77b --- /dev/null +++ b/main.py @@ -0,0 +1,23 @@ +from bluepy.btle import Peripheral, ADDR_TYPE_PUBLIC +import time +import colorsys +import json + +lampmac = "FC:58:FA:A1:CF:F1" + +dev = Peripheral(lampmac, ADDR_TYPE_PUBLIC) + +def makemsg(r, g, b, l=0): + return bytearray((b"\x01" if g > 0 else b"\x00") + bytes([g]) +\ + b"\x00\x00" +\ + (b"\x01" if b > 0 else b"\x00") + bytes([b]) +\ + (b"\x01" if r > 0 else b"\x00") + bytes([r]) +\ + (b"\x01" if l > 0 else b"\x00") + bytes([l])) + +hue = 0 +while True: + hue = (hue + 1) % 360 + r, g, b = map(lambda x: int(x * 255), colorsys.hsv_to_rgb(hue / 360, 1, 1)) + + color = makemsg(r, g, b) + dev.writeCharacteristic(0x002A, color) -- cgit v1.2.3