Browse Source

in which i give up and go with the current state of blinking

Brennen Bearnes 1 year ago
parent
commit
9db53e233d
4 changed files with 45 additions and 42 deletions
  1. 3
    2
      Makefile
  2. 4
    0
      blinkenring.py
  3. 36
    38
      rings.py
  4. 2
    2
      wzrd_util.py

+ 3
- 2
Makefile View File

@@ -3,9 +3,10 @@ target = /media/brennen/CIRCUITPY
3 3
 # wizard staff rings
4 4
 ring:
5 5
 	cp rings.py $(target)/main.py
6
+	cp wzrd_util.py $(target)/
6 7
 	cp blinkenring.py $(target)
7
-	if [ -d $(target)/lib ]; then rm -r $(target)/lib
8
-	cp -r lib $(target)
8
+#if [ -d $(target)/lib ]; then rm -r $(target)/lib; fi
9
+#cp -r lib $(target)
9 10
 	sync
10 11
 
11 12
 # little 8-pixel stick

+ 4
- 0
blinkenring.py View File

@@ -36,6 +36,10 @@ class BlinkenRing:
36 36
     def get_color(self):
37 37
         return (self.red, self.green, self.blue)
38 38
 
39
+    def go_blank(self):
40
+        self.pixels.fill((0, 0, 0))
41
+        self.pixels.show()
42
+
39 43
     # Advance one frame of animation:
40 44
     def animate(self):
41 45
         if self.party_mode:

+ 36
- 38
rings.py View File

@@ -1,56 +1,54 @@
1
+from wzrd_util import *
2
+
3
+# Accelerometer stuff not used at the moment:
4
+# import adafruit_lis3dh
5
+# import digitalio
6
+
1 7
 import adafruit_thermistor
2 8
 import analogio
9
+import blinkenring
3 10
 import board
11
+import busio
4 12
 import neopixel
5 13
 import time
6 14
 import urandom
7 15
 
8
-from wzrd import *
9
-import blinkenring
10
-
11
-# Initial setup:
12
-brightness_high = 0.2
13
-brightness_low = 0.05
14
-offset = 0
15
-pixel_off = (0, 0, 0);
16
-color = (60, 60, 60);
17
-tick_duration = 0.1
16
+# Hardware SPI setup for accelerometer, maybe (does not work):
17
+# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
18
+# cs = digitalio.DigitalInOut(board.D8)  # Set to appropriate CS pin!
19
+# lis3dh = adafruit_lis3dh.LIS3DH_SPI(spi, cs)
18 20
 
19 21
 # https://github.com/adafruit/Adafruit_CircuitPython_Thermistor
20 22
 thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25, 3950)
21 23
 
22 24
 random_pin = analogio.AnalogIn(board.A4)
23
-
24 25
 photocell = analogio.AnalogIn(board.A8)
25 26
 
26
-ext_pixels = blinkenring.BlinkenRing(board.A3, 24, 6)
27
-onboard_pixels = blinkenring.BlinkenRing(board.NEOPIXEL, 10, 5)
28
-# ext_pixels.party_mode = True
29
-# onboard_pixels.party_mode = True
30
-
31
-last_temp = thermistor.temperature
27
+# Initial setup:
28
+tick_duration = 0.1
32 29
 last_photocell = photocell_value(photocell)
33
-last_colorswitch = 0
30
+frame = 0
31
+max_frame = 30
32
+max_bright = 0.35
33
+
34
+ext_ring = blinkenring.BlinkenRing(board.A3, 24, 6)
35
+onboard_ring = blinkenring.BlinkenRing(board.NEOPIXEL, 10, 5)
36
+# ext_ring.party_mode = True
37
+# onboard_ring.party_mode = True
38
+
34 39
 while True:
35
-    t = time.monotonic()
36
-    ext_pixels.animate()
37
-    onboard_pixels.animate()
38
-
39
-    switch = False
40
-
41
-    if (t - last_colorswitch) > 60:
42
-        ext_pixels.randomize_color()
43
-        onboard_pixels.randomize_color()
44
-        switch = True
45
-
46
-    current_temp = thermistor.temperature
47
-    if abs(last_temp - current_temp) > 1:
48
-        onboard_pixels.set_color(wzrd.get_color_for_temp(thermistor.temperature))
49
-        switch = True
50
-    last_temp = current_temp
51
-    # print(last_temp, current_temp)
52
-
53
-    if switch:
54
-        last_colorswitch = t
40
+    frame += 1
41
+    ext_ring.animate()
42
+    onboard_ring.animate()
43
+
44
+    if frame == int(max_frame / 2):
45
+        ext_ring.set_color(get_color_for_temp(thermistor.temperature))
46
+
47
+    # reset frame counter
48
+    if frame > max_frame:
49
+        urandom.seed(random_pin.value)
50
+        onboard_ring.set_color(ext_ring.get_color())
51
+        ext_ring.randomize_color()
52
+        frame = 0
55 53
 
56 54
     time.sleep(tick_duration)

wzrd.py → wzrd_util.py View File

@@ -8,9 +8,9 @@ def get_color_for_temp(temp_current):
8 8
     temp_range = temp_hot - temp_cold
9 9
 
10 10
     if temp_current >= temp_hot:
11
-        return (50, 0, 0)
11
+        return (80, 0, 0)
12 12
     elif temp_current <= temp_cold:
13
-        return (0, 0, 50)
13
+        return (0, 0, 80)
14 14
     else:
15 15
         return get_color_in_range(temp_cold, temp_hot, temp_current)
16 16