Browse Source

add gemma m0 8-pixel stick project, shuffle code a bit

Brennen Bearnes 1 year ago
parent
commit
d1794855a1
7 changed files with 30 additions and 19 deletions
  1. 11
    2
      Makefile
  2. 1
    1
      blinkenring.py
  3. BIN
      gemma_lib/dotstar.mpy
  4. BIN
      gemma_lib/neopixel.mpy
  5. 4
    15
      rings.py
  6. 10
    0
      stick.py
  7. 4
    1
      wzrd.py

+ 11
- 2
Makefile View File

@@ -1,3 +1,12 @@
1
-all:
2
-	cp *.py /media/brennen/CIRCUITPY/
1
+# wizard staff rings
2
+ring:
3
+	cp rings.py /media/brennen/CIRCUITPY/main.py
4
+	cp blinkenring.py /media/brennen/CIRCUITPY/
5
+	sync
6
+
7
+# little 8-pixel stick
8
+stick:
9
+	cp stick.py /media/brennen/CIRCUITPY/main.py
10
+	cp blinkenring.py /media/brennen/CIRCUITPY/
11
+	cp -r gemma_lib /media/brennen/CIRCUITPY/lib
3 12
 	sync

WizardRing.py → blinkenring.py View File

@@ -1,7 +1,7 @@
1 1
 import urandom
2 2
 import neopixel
3 3
 
4
-class WizardRing:
4
+class BlinkenRing:
5 5
 
6 6
     def __init__(self, pin, pixel_count, pixel_spacer):
7 7
         self.party_mode = False

BIN
gemma_lib/dotstar.mpy View File


BIN
gemma_lib/neopixel.mpy View File


main.py → rings.py View File

@@ -3,10 +3,10 @@ import analogio
3 3
 import board
4 4
 import neopixel
5 5
 import time
6
-import wzrd
7 6
 import urandom
8 7
 
9
-import WizardRing
8
+from wzrd import *
9
+import blinkenring
10 10
 
11 11
 # Initial setup:
12 12
 brightness_high = 0.2
@@ -22,11 +22,9 @@ thermistor = adafruit_thermistor.Thermistor(board.TEMPERATURE, 10000, 10000, 25,
22 22
 random_pin = analogio.AnalogIn(board.A4)
23 23
 
24 24
 photocell = analogio.AnalogIn(board.A8)
25
-def photocell_value(input):
26
-    return input.value * 330 // (2 ** 16)
27 25
 
28
-ext_pixels = WizardRing.WizardRing(board.A3, 24, 6)
29
-onboard_pixels = WizardRing.WizardRing(board.NEOPIXEL, 10, 5)
26
+ext_pixels = blinkenring.BlinkenRing(board.A3, 24, 6)
27
+onboard_pixels = blinkenring.BlinkenRing(board.NEOPIXEL, 10, 5)
30 28
 # ext_pixels.party_mode = True
31 29
 # onboard_pixels.party_mode = True
32 30
 
@@ -45,15 +43,6 @@ while True:
45 43
         onboard_pixels.randomize_color()
46 44
         switch = True
47 45
 
48
-#   current_photocell = photocell_value(photocell)
49
-#   if abs(last_photocell - current_photocell) > 10:
50
-#       onboard_pixels.set_color(ext_pixels.get_color())
51
-#       urandom.seed(random_pin.value)
52
-#       ext_pixels.randomize_color()
53
-#       switch = True
54
-#   last_photocell = current_photocell
55
-#   # print(last_photocell, current_photocell)
56
-
57 46
     current_temp = thermistor.temperature
58 47
     if abs(last_temp - current_temp) > 1:
59 48
         onboard_pixels.set_color(wzrd.get_color_for_temp(thermistor.temperature))

+ 10
- 0
stick.py View File

@@ -0,0 +1,10 @@
1
+import board
2
+import blinkenring
3
+import dotstar
4
+import neopixel
5
+import time
6
+
7
+stick = blinkenring.BlinkenRing(board.D0, 8, 4)
8
+while True:
9
+    stick.animate()
10
+    time.sleep(0.5)

+ 4
- 1
wzrd.py View File

@@ -12,7 +12,7 @@ def get_color_for_temp(temp_current):
12 12
     else:
13 13
         return get_color_in_range(temp_cold, temp_hot, temp_current)
14 14
 
15
-def get_color_in_range (minimum, maximum, value):
15
+def get_color_in_range(minimum, maximum, value):
16 16
     max_color_val = 30
17 17
 
18 18
     minimum, maximum = float(minimum), float(maximum)
@@ -21,3 +21,6 @@ def get_color_in_range (minimum, maximum, value):
21 21
     r = int(max(0, max_color_val * (ratio - 1)))
22 22
     g = max_color_val - b - r
23 23
     return (r, g, b)
24
+
25
+def photocell_value(input):
26
+    return input.value * 330 // (2 ** 16)