From 9be32ba1adad612ca758898e7521c88cddc763de Mon Sep 17 00:00:00 2001 From: Salvatore La Bua Date: Sat, 23 Mar 2024 23:11:34 +0900 Subject: [PATCH] Initial support for neopixel rpm and compass modes --- OLED/picomotodash_neopx.py | 29 ++++++++++++++++++++++++++--- OLED/picomotodash_oled_ws10d.py | 3 ++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/OLED/picomotodash_neopx.py b/OLED/picomotodash_neopx.py index 9d26985..3511607 100644 --- a/OLED/picomotodash_neopx.py +++ b/OLED/picomotodash_neopx.py @@ -12,6 +12,9 @@ NUM_LEDS = 37 RGBW = False +MODE_RPM = 0 +MODE_COMPASS = 1 + class NEOPX: @@ -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 @@ -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) @@ -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() diff --git a/OLED/picomotodash_oled_ws10d.py b/OLED/picomotodash_oled_ws10d.py index b92db47..5aaeb32 100644 --- a/OLED/picomotodash_oled_ws10d.py +++ b/OLED/picomotodash_oled_ws10d.py @@ -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)