瀏覽代碼

Initial commit

master
The Dod 2 年之前
當前提交
b917f2cad1
共有 3 個檔案被更改,包括 89 行新增0 行删除
  1. 12
    0
      README.md
  2. 77
    0
      code.py
  3. 二進制
      movalite.jpg

+ 12
- 0
README.md 查看文件

@@ -0,0 +1,12 @@
1
+[Adafruit Circuit Playground Bluefruit](https://learn.adafruit.com/adafruit-circuit-playground-bluefruit) motion-sensitiuve "bling".
2
+The RGB levels of neopixels around the circuit are affected by X/Y/Z acceleration.
3
+
4
+Controls:
5
+
6
+ *  slider switch: normal/standby mode
7
+ *  button a: increase brightness
8
+ *  button b: decrease brightness
9
+
10
+Physical design by [Impulsiva](https://www.impulsiva.com/)
11
+
12
+![Movalite](movalite.jpg)

+ 77
- 0
code.py 查看文件

@@ -0,0 +1,77 @@
1
+"""
2
+Movalite by The Dod:
3
+Adafruit CircuitPlayground Bluefruit motion-sensitiuve "bling"
4
+The RGB levels of neopixels around the circuit are affected
5
+by X/Y/Z acceleration
6
+
7
+Controls:
8
+    slider switch: normal/standby mode
9
+    button a: increase brightness
10
+    button b: decrease brightness
11
+"""
12
+import math
13
+import time
14
+from adafruit_circuitplayground import cp
15
+
16
+NUM_PIXELS = 10
17
+# Like a clock, with connectors at 12 (USB) and 6 (power)
18
+LED_ANGLES = [
19
+    i*math.pi/6.0
20
+    for i in [11, 10, 9, 8, 7, 5, 4, 3, 2, 1]]
21
+
22
+minx = miny = minz = -5.0
23
+maxx = maxy = maxz = 5.0
24
+
25
+cp.pixels.brightness = 0.1
26
+
27
+is_standby = cp.switch
28
+last_click = 0
29
+DEBOUNCE = 0.25
30
+
31
+def angles2level(led, val):
32
+    led_angle = LED_ANGLES[led]
33
+    val_angle = val * 2.0 * math.pi
34
+    angle = led_angle - val_angle
35
+    while angle > 2 * math.pi:
36
+        angle -= 2*math.pi
37
+    # the pow() makes sin() values sharper
38
+    return int(255*pow(math.sin(angle/2), 4))
39
+
40
+while True:
41
+    if time.monotonic() > last_click+DEBOUNCE:
42
+        if is_standby != cp.switch:
43
+            is_standby = cp.switch
44
+            last_click = time.monotonic()
45
+            if is_standby:
46
+                for i in range(NUM_PIXELS):
47
+                    cp.pixels[i] = (0, 0, 0)
48
+        if cp.button_b:
49
+            last_click = time.monotonic()
50
+            cp.pixels.brightness = max(0.05, cp.pixels.brightness*0.9)
51
+        elif cp.button_a:
52
+            last_click = time.monotonic()
53
+            cp.pixels.brightness = min(0.95, 1.0-(1.0-cp.pixels.brightness)*0.9)
54
+    if not is_standby:
55
+        x, y, z = cp.acceleration
56
+        if x < minx:
57
+            minx = x
58
+        if y < miny:
59
+            miny = y
60
+        if z < minz:
61
+            minz = z
62
+        if x > maxx:
63
+            maxx = x
64
+        if y > maxy:
65
+            maxy = y
66
+        if z > maxz:
67
+            maxz = z
68
+        vals = (
69
+            (x-minx)/(maxx-minx),
70
+            (y-miny)/(maxy-miny),
71
+            (z-minz)/(maxz-minz))
72
+        for i in range(NUM_PIXELS):
73
+            cp.pixels[i] = (
74
+                angles2level(i, vals[0]),
75
+                angles2level(i, vals[1]),
76
+                angles2level(i, vals[2]))
77
+    time.sleep(0.01)

二進制
movalite.jpg 查看文件


Loading…
取消
儲存