Skip to content

Commit

Permalink
Initial support for neopixel rpm and compass modes
Browse files Browse the repository at this point in the history
  • Loading branch information
slabua committed Mar 23, 2024
1 parent 1f1a718 commit 9be32ba
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
29 changes: 26 additions & 3 deletions OLED/picomotodash_neopx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
NUM_LEDS = 37
RGBW = False

MODE_RPM = 0
MODE_COMPASS = 1


class NEOPX:

Expand All @@ -20,6 +23,8 @@ def __init__(self, pin=PIN_NUM, n=NUM_LEDS, rgbw=RGBW):
self.n = n
self.np = neopixel.NeoPixel(Pin(pin), n, bpp=4 if rgbw else 3, timing=1)

self.mode = MODE_COMPASS

def map_range(self, value, in_range, out_range):
(a, b), (c, d) = in_range, out_range
return (value - a) / (b - a) * (d - c) + c
Expand All @@ -28,8 +33,8 @@ def set_np(self, i, rgb_tuple):
self.np[i] = rgb_tuple
self.np.write()

def set_np_rpm(self, value):
upto = value // 1000
def set_np_rpm(self, rpm):
upto = rpm // 1000
for i in range(24, self.n):
if i < upto + 24:
self.np[i] = (2, 2, 0)
Expand All @@ -38,7 +43,25 @@ def set_np_rpm(self, value):

self.np.write()

def reset(self):
def set_np_compass(self, heading):
# PLACEHOLDER
# TODO Update logic
for i in range(24, self.n):
self.np[i] = (0, 0, 0)

i = int(self.map_range(heading, (0, 360), (34, 24)))

self.np[i] = (0, 0, 5)

self.np.write()

def update(self, value):
if self.mode == MODE_RPM:
self.set_np_rpm(value)
elif self.mode == MODE_COMPASS:
self.set_np_compass(value)

def off(self):
for i in range(self.n):
self.np[i] = (0, 0, 0)
self.np.write()
Expand Down
3 changes: 2 additions & 1 deletion OLED/picomotodash_oled_ws10d.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,11 +443,12 @@ def thread1(PWM2RPM_FACTOR):
# sleep(0.1)
read_gps()

# HEADING = calculate_heading()
read_mpu()
HEADING = mpu.heading
HEADING = moving_avg(5) # 9

# neopixel_ring.update(HEADING)

# print(key0.value(), key1.value())

display.fill(0)
Expand Down

0 comments on commit 9be32ba

Please sign in to comment.