From 6672e9d68381a79dab0747243056d18942e272de Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 17 Aug 2021 12:48:45 +0100 Subject: [PATCH 01/10] Added pins for user sw and current sense --- micropython/modules/plasma_2040/plasma_2040.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/micropython/modules/plasma_2040/plasma_2040.c b/micropython/modules/plasma_2040/plasma_2040.c index c606f0f9..6f651da0 100644 --- a/micropython/modules/plasma_2040/plasma_2040.c +++ b/micropython/modules/plasma_2040/plasma_2040.c @@ -68,6 +68,8 @@ STATIC const mp_map_elem_t plasma_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PIN_LED_B), MP_ROM_INT(18) }, { MP_ROM_QSTR(MP_QSTR_PIN_BUTTON_A), MP_ROM_INT(12) }, { MP_ROM_QSTR(MP_QSTR_PIN_BUTTON_B), MP_ROM_INT(13) }, + { MP_ROM_QSTR(MP_QSTR_PIN_USER_SW), MP_ROM_INT(23) }, + { MP_ROM_QSTR(MP_QSTR_PIN_CURRENT_SENSE), MP_ROM_INT(29) }, { MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_RGB), MP_ROM_INT(0x00) }, { MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_RBG), MP_ROM_INT(0x01) }, From 78952ff070f088a00922ac307ec54522e3e48e66 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 17 Aug 2021 12:59:36 +0100 Subject: [PATCH 02/10] Changed rgb to use full pwm range --- micropython/modules_py/pimoroni.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython/modules_py/pimoroni.py b/micropython/modules_py/pimoroni.py index 643b5caf..1b6fe06f 100644 --- a/micropython/modules_py/pimoroni.py +++ b/micropython/modules_py/pimoroni.py @@ -80,6 +80,6 @@ class RGBLED: r = 255 - r g = 255 - g b = 255 - b - self.led_r.duty_u16(r * 255) - self.led_g.duty_u16(g * 255) - self.led_b.duty_u16(b * 255) + self.led_r.duty_u16((r * 65535) / 255) + self.led_g.duty_u16((g * 65535) / 255) + self.led_b.duty_u16((b * 65535) / 255) From 5a911ad46e2e7108ca652a88a9107fe91d5ad49d Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 17 Aug 2021 13:07:34 +0100 Subject: [PATCH 03/10] Fix for "Changed rgb to use full pwm range" --- micropython/modules_py/pimoroni.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micropython/modules_py/pimoroni.py b/micropython/modules_py/pimoroni.py index 1b6fe06f..9dd3c634 100644 --- a/micropython/modules_py/pimoroni.py +++ b/micropython/modules_py/pimoroni.py @@ -80,6 +80,6 @@ class RGBLED: r = 255 - r g = 255 - g b = 255 - b - self.led_r.duty_u16((r * 65535) / 255) - self.led_g.duty_u16((g * 65535) / 255) - self.led_b.duty_u16((b * 65535) / 255) + self.led_r.duty_u16(int((r * 65535) / 255)) + self.led_g.duty_u16(int((g * 65535) / 255)) + self.led_b.duty_u16(int((b * 65535) / 255)) From e045cb9615227feb145ba965065325ff92a2cf3f Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 17 Aug 2021 13:25:46 +0100 Subject: [PATCH 04/10] Updated plasma mp examples to use user_sw and current sensing --- micropython/examples/plasma_2040/rainbow.py | 19 +++++++++++++++++-- .../plasma_2040/rgb-led-and-buttons.py | 8 ++++++-- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/micropython/examples/plasma_2040/rainbow.py b/micropython/examples/plasma_2040/rainbow.py index 89e93dc4..2e88281c 100644 --- a/micropython/examples/plasma_2040/rainbow.py +++ b/micropython/examples/plasma_2040/rainbow.py @@ -1,19 +1,34 @@ import plasma import time +# Import helper for Analog +from pimoroni import Analog + NUM_LEDS = 30 +UPDATES = 60 # WS2812 / NeoPixel™ LEDs led_strip = plasma.WS2812(NUM_LEDS, 0, 0, 15) # APA102 / DotStar™ LEDs -# led_strip = plasma.APA102(NUM_LEDS, 0, 0, 15, 14) +#led_strip = plasma.APA102(NUM_LEDS, 0, 0, 15, 14) + +# Set up the ADC for reading current +sense = Analog(plasma.PIN_CURRENT_SENSE, plasma.ADC_GAIN, plasma.SHUNT_RESISTOR) # Start updating the LED strip led_strip.start() +count = 0 # Make rainbows while True: t = time.ticks_ms() / 1000.0 / 5.0 for i in range(NUM_LEDS): led_strip.set_hsv(i, t + (i / NUM_LEDS)) - time.sleep(1.0 / 60) + + count += 1 + if count >= UPDATES: + # Display the current value once every second + print("Current =", sense.read_current(), "A") + count = 0 + + time.sleep(1.0 / UPDATES) diff --git a/micropython/examples/plasma_2040/rgb-led-and-buttons.py b/micropython/examples/plasma_2040/rgb-led-and-buttons.py index a6d4501e..f4efa456 100644 --- a/micropython/examples/plasma_2040/rgb-led-and-buttons.py +++ b/micropython/examples/plasma_2040/rgb-led-and-buttons.py @@ -1,18 +1,22 @@ import time # Import pin constants from plasma -from plasma import PIN_LED_R, PIN_LED_G, PIN_LED_B, PIN_BUTTON_A, PIN_BUTTON_B +from plasma import PIN_LED_R, PIN_LED_G, PIN_LED_B, PIN_USER_SW, PIN_BUTTON_A, PIN_BUTTON_B # Import helpers for RGB LEDs and Buttons from pimoroni import RGBLED, Button led = RGBLED(PIN_LED_R, PIN_LED_G, PIN_LED_B) -led.set_rgb(255, 0, 0) +led.set_rgb(0, 0, 0) +user_sw = Button(PIN_USER_SW) button_a = Button(PIN_BUTTON_A) button_b = Button(PIN_BUTTON_B) while True: + if user_sw.read(): + print("Pressed User SW - {}".format(time.ticks_ms())) + led.set_rgb(255, 0, 0) if button_a.read(): print("Pressed A - {}".format(time.ticks_ms())) led.set_rgb(0, 255, 0) From 71e95805fa9d24823eb152ae5260c4ef20447843 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Tue, 17 Aug 2021 13:43:42 +0100 Subject: [PATCH 05/10] Linting fixes --- micropython/examples/plasma_2040/rainbow.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/micropython/examples/plasma_2040/rainbow.py b/micropython/examples/plasma_2040/rainbow.py index 2e88281c..d364f433 100644 --- a/micropython/examples/plasma_2040/rainbow.py +++ b/micropython/examples/plasma_2040/rainbow.py @@ -10,7 +10,7 @@ UPDATES = 60 # WS2812 / NeoPixel™ LEDs led_strip = plasma.WS2812(NUM_LEDS, 0, 0, 15) # APA102 / DotStar™ LEDs -#led_strip = plasma.APA102(NUM_LEDS, 0, 0, 15, 14) +# led_strip = plasma.APA102(NUM_LEDS, 0, 0, 15, 14) # Set up the ADC for reading current sense = Analog(plasma.PIN_CURRENT_SENSE, plasma.ADC_GAIN, plasma.SHUNT_RESISTOR) @@ -30,5 +30,5 @@ while True: # Display the current value once every second print("Current =", sense.read_current(), "A") count = 0 - + time.sleep(1.0 / UPDATES) From 49b944a40a5b4395aeb13ca39a3c8aef152fef30 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Wed, 18 Aug 2021 10:54:31 +0100 Subject: [PATCH 06/10] Added user button to rainbow example --- examples/plasma_2040/plasma2040_rainbow.cpp | 26 ++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/examples/plasma_2040/plasma2040_rainbow.cpp b/examples/plasma_2040/plasma2040_rainbow.cpp index ac189208..bdeef29d 100644 --- a/examples/plasma_2040/plasma2040_rainbow.cpp +++ b/examples/plasma_2040/plasma2040_rainbow.cpp @@ -13,6 +13,7 @@ /* Press "B" to speed up the LED cycling effect. Press "A" to slow it down again. +Press "Boot" to reset the speed back to default. */ using namespace pimoroni; @@ -20,6 +21,12 @@ using namespace pimoroni; // Set how many LEDs you have const uint N_LEDS = 30; +// The speed that the LEDs will start cycling at +const uint DEFAULT_SPEED = 10; + +// How many times the LEDs will be updated per second +const uint UPDATES = 60; + // Pick *one* LED type by uncommenting the relevant line below: // APA102-style LEDs with Data/Clock lines. AKA DotStar @@ -29,6 +36,7 @@ const uint N_LEDS = 30; // by default the WS2812 LED strip will be 400KHz, RGB with no white element plasma::WS2812 led_strip(N_LEDS, pio0, 0, plasma::PIN_DAT); +Button user_sw(plasma::USER_SW, Polarity::ACTIVE_LOW, 0); Button button_a(plasma::BUTTON_A, Polarity::ACTIVE_LOW, 50); Button button_b(plasma::BUTTON_B, Polarity::ACTIVE_LOW, 50); RGBLED led(plasma::LED_R, plasma::LED_G, plasma::LED_B); @@ -37,17 +45,23 @@ RGBLED led(plasma::LED_R, plasma::LED_G, plasma::LED_B); int main() { stdio_init_all(); - led_strip.start(60); + led_strip.start(UPDATES); - int speed = 10; + int speed = DEFAULT_SPEED; float offset = 0.0f; while (true) { + bool sw = user_sw.read(); bool a = button_a.read(); bool b = button_b.read(); - - if(a) speed--; - if(b) speed++; + + if(sw) { + speed = DEFAULT_SPEED; + } + else { + if(a) speed--; + if(b) speed++; + } speed = std::min((int)255, std::max((int)1, speed)); offset += float(speed) / 2000.0f; @@ -61,6 +75,6 @@ int main() { // Sleep time controls the rate at which the LED buffer is updated // but *not* the actual framerate at which the buffer is sent to the LEDs - sleep_ms(1000 / 60); + sleep_ms(1000 / UPDATES); } } From 84acf406a29bc5953ec99d08706e8d4c7140765b Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Wed, 18 Aug 2021 11:59:22 +0100 Subject: [PATCH 07/10] Added Dat and Clk defines --- micropython/modules/plasma_2040/plasma_2040.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/micropython/modules/plasma_2040/plasma_2040.c b/micropython/modules/plasma_2040/plasma_2040.c index 6f651da0..5b1bb383 100644 --- a/micropython/modules/plasma_2040/plasma_2040.c +++ b/micropython/modules/plasma_2040/plasma_2040.c @@ -69,6 +69,8 @@ STATIC const mp_map_elem_t plasma_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PIN_BUTTON_A), MP_ROM_INT(12) }, { MP_ROM_QSTR(MP_QSTR_PIN_BUTTON_B), MP_ROM_INT(13) }, { MP_ROM_QSTR(MP_QSTR_PIN_USER_SW), MP_ROM_INT(23) }, + { MP_ROM_QSTR(MP_QSTR_PIN_CLK), MP_ROM_INT(14) }, + { MP_ROM_QSTR(MP_QSTR_PIN_DAT), MP_ROM_INT(15) }, { MP_ROM_QSTR(MP_QSTR_PIN_CURRENT_SENSE), MP_ROM_INT(29) }, { MP_ROM_QSTR(MP_QSTR_COLOR_ORDER_RGB), MP_ROM_INT(0x00) }, From fa17f2e77e521b245cdc5c540e4c9d797416b652 Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Wed, 18 Aug 2021 12:16:51 +0100 Subject: [PATCH 08/10] Added analog class for plasma current reading --- drivers/CMakeLists.txt | 1 + drivers/analog/CMakeLists.txt | 1 + drivers/analog/analog.cmake | 11 +++++++++++ drivers/analog/analog.cpp | 18 ++++++++++++++++++ drivers/analog/analog.hpp | 31 +++++++++++++++++++++++++++++++ 5 files changed, 62 insertions(+) create mode 100644 drivers/analog/CMakeLists.txt create mode 100644 drivers/analog/analog.cmake create mode 100644 drivers/analog/analog.cpp create mode 100644 drivers/analog/analog.hpp diff --git a/drivers/CMakeLists.txt b/drivers/CMakeLists.txt index 58a2bbd3..88d0b099 100644 --- a/drivers/CMakeLists.txt +++ b/drivers/CMakeLists.txt @@ -1,3 +1,4 @@ +add_subdirectory(analog) add_subdirectory(esp32spi) add_subdirectory(ioexpander) add_subdirectory(ltp305) diff --git a/drivers/analog/CMakeLists.txt b/drivers/analog/CMakeLists.txt new file mode 100644 index 00000000..06d94443 --- /dev/null +++ b/drivers/analog/CMakeLists.txt @@ -0,0 +1 @@ +include(analog.cmake) \ No newline at end of file diff --git a/drivers/analog/analog.cmake b/drivers/analog/analog.cmake new file mode 100644 index 00000000..69caf0a6 --- /dev/null +++ b/drivers/analog/analog.cmake @@ -0,0 +1,11 @@ +set(DRIVER_NAME analog) +add_library(${DRIVER_NAME} INTERFACE) + +target_sources(${DRIVER_NAME} INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/${DRIVER_NAME}.cpp +) + +target_include_directories(${DRIVER_NAME} INTERFACE ${CMAKE_CURRENT_LIST_DIR}) + +# Pull in pico libraries that we need +target_link_libraries(${DRIVER_NAME} INTERFACE pico_stdlib hardware_adc) \ No newline at end of file diff --git a/drivers/analog/analog.cpp b/drivers/analog/analog.cpp new file mode 100644 index 00000000..f3179a7e --- /dev/null +++ b/drivers/analog/analog.cpp @@ -0,0 +1,18 @@ +#include "analog.hpp" + +namespace pimoroni { + uint16_t Analog::read_raw() { + return adc_read(); + } + + float Analog::read_voltage() { + return ((float)adc_read() * 3.3f) / (1 << 12) / amplifier_gain; + } + + float Analog::read_current() { + if(resistor > 0.0f) + return read_voltage() / resistor; + else + return read_voltage(); + } +}; \ No newline at end of file diff --git a/drivers/analog/analog.hpp b/drivers/analog/analog.hpp new file mode 100644 index 00000000..cad26e46 --- /dev/null +++ b/drivers/analog/analog.hpp @@ -0,0 +1,31 @@ +#pragma once + +#include +#include "pico/stdlib.h" +#include "hardware/adc.h" +#include "common/pimoroni_common.hpp" + +namespace pimoroni { + + class Analog { + public: + Analog(uint pin, float amplifier_gain = 1.0f, float resistor = 0.0f) : + pin(pin), amplifier_gain(amplifier_gain), resistor(resistor) { + adc_init(); + + //Make sure GPIO is high-impedance, no pullups etc + adc_gpio_init(pin); + + //Select ADC input 0 (GPIO26) + adc_select_input(pin - 26); + }; + uint16_t read_raw(); + float read_voltage(); + float read_current(); + private: + uint pin; + float amplifier_gain; + float resistor; + }; + +} \ No newline at end of file From fa4cf86126d2b73d8b09ace0e131119dc41faece Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Wed, 18 Aug 2021 12:18:25 +0100 Subject: [PATCH 09/10] Updated rainbow example to be consistant across languages --- examples/plasma_2040/plasma2040_rainbow.cmake | 11 +++- examples/plasma_2040/plasma2040_rainbow.cpp | 11 ++++ libraries/plasma2040/plasma2040.hpp | 7 +++ micropython/examples/plasma_2040/rainbow.py | 56 ++++++++++++++++--- 4 files changed, 73 insertions(+), 12 deletions(-) diff --git a/examples/plasma_2040/plasma2040_rainbow.cmake b/examples/plasma_2040/plasma2040_rainbow.cmake index c0558e65..ceb1bd09 100644 --- a/examples/plasma_2040/plasma2040_rainbow.cmake +++ b/examples/plasma_2040/plasma2040_rainbow.cmake @@ -1,10 +1,15 @@ -add_executable(plasma2040_rainbow plasma2040_rainbow.cpp) +set(OUTPUT_NAME plasma2040_rainbow) +add_executable(${OUTPUT_NAME} plasma2040_rainbow.cpp) -target_link_libraries(plasma2040_rainbow +target_link_libraries(${OUTPUT_NAME} pico_stdlib plasma2040 rgbled button + analog ) -pico_add_extra_outputs(plasma2040_rainbow) +# enable usb output +pico_enable_stdio_usb(${OUTPUT_NAME} 1) + +pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/plasma_2040/plasma2040_rainbow.cpp b/examples/plasma_2040/plasma2040_rainbow.cpp index bdeef29d..13b4799d 100644 --- a/examples/plasma_2040/plasma2040_rainbow.cpp +++ b/examples/plasma_2040/plasma2040_rainbow.cpp @@ -9,6 +9,7 @@ #include "common/pimoroni_common.hpp" #include "rgbled.hpp" #include "button.hpp" +#include "analog.hpp" /* Press "B" to speed up the LED cycling effect. @@ -27,6 +28,7 @@ const uint DEFAULT_SPEED = 10; // How many times the LEDs will be updated per second const uint UPDATES = 60; + // Pick *one* LED type by uncommenting the relevant line below: // APA102-style LEDs with Data/Clock lines. AKA DotStar @@ -40,6 +42,7 @@ Button user_sw(plasma::USER_SW, Polarity::ACTIVE_LOW, 0); Button button_a(plasma::BUTTON_A, Polarity::ACTIVE_LOW, 50); Button button_b(plasma::BUTTON_B, Polarity::ACTIVE_LOW, 50); RGBLED led(plasma::LED_R, plasma::LED_G, plasma::LED_B); +Analog sense(plasma::PIN_SENSE, plasma::ADC_GAIN, plasma::SHUNT_RESISTOR); int main() { @@ -50,6 +53,7 @@ int main() { int speed = DEFAULT_SPEED; float offset = 0.0f; + uint count = 0; while (true) { bool sw = user_sw.read(); bool a = button_a.read(); @@ -73,6 +77,13 @@ int main() { led.set_rgb(speed, 0, 255 - speed); + count += 1; + if(count >= UPDATES) { + // Display the current value once every second + printf("Current = %f A\n", sense.read_current()); + count = 0; + } + // Sleep time controls the rate at which the LED buffer is updated // but *not* the actual framerate at which the buffer is sent to the LEDs sleep_ms(1000 / UPDATES); diff --git a/libraries/plasma2040/plasma2040.hpp b/libraries/plasma2040/plasma2040.hpp index d57a66e8..c4d14272 100644 --- a/libraries/plasma2040/plasma2040.hpp +++ b/libraries/plasma2040/plasma2040.hpp @@ -12,6 +12,13 @@ const uint LED_B = 18; const uint BUTTON_A = 12; const uint BUTTON_B = 13; +const uint USER_SW = 23; + const uint PIN_CLK = 14; // Used only for APA102 const uint PIN_DAT = 15; // Used for both APA102 and WS2812 + +const uint PIN_SENSE = 29; // The pin used for current sensing + +constexpr float ADC_GAIN = 50; +constexpr float SHUNT_RESISTOR = 0.015f; } \ No newline at end of file diff --git a/micropython/examples/plasma_2040/rainbow.py b/micropython/examples/plasma_2040/rainbow.py index d364f433..40b0b80f 100644 --- a/micropython/examples/plasma_2040/rainbow.py +++ b/micropython/examples/plasma_2040/rainbow.py @@ -1,29 +1,67 @@ import plasma import time -# Import helper for Analog -from pimoroni import Analog +# Import helpers for RGB LEDs, Buttons, and Analog +from pimoroni import RGBLED, Button, Analog +# Press "B" to speed up the LED cycling effect. +# Press "A" to slow it down again. +# Press "Boot" to reset the speed back to default. + +# Set how many LEDs you have NUM_LEDS = 30 + +# The speed that the LEDs will start cycling at +DEFAULT_SPEED = 10 + +# How many times the LEDs will be updated per second UPDATES = 60 -# WS2812 / NeoPixel™ LEDs -led_strip = plasma.WS2812(NUM_LEDS, 0, 0, 15) -# APA102 / DotStar™ LEDs -# led_strip = plasma.APA102(NUM_LEDS, 0, 0, 15, 14) -# Set up the ADC for reading current +# Pick *one* LED type by uncommenting the relevant line below: + +# APA102 / DotStar™ LEDs +# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma.PIN_DAT, plasma.PIN_CLK) + +# WS2812 / NeoPixel™ LEDs +led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma.PIN_DAT) + +user_sw = Button(plasma.PIN_USER_SW) +button_a = Button(plasma.PIN_BUTTON_A) +button_b = Button(plasma.PIN_BUTTON_B) +led = RGBLED(plasma.PIN_LED_R, plasma.PIN_LED_G, plasma.PIN_LED_B) sense = Analog(plasma.PIN_CURRENT_SENSE, plasma.ADC_GAIN, plasma.SHUNT_RESISTOR) # Start updating the LED strip led_strip.start() +speed = DEFAULT_SPEED +offset = 0.0 + count = 0 # Make rainbows while True: - t = time.ticks_ms() / 1000.0 / 5.0 + sw = user_sw.read() + a = button_a.read() + b = button_b.read() + + if sw: + speed = DEFAULT_SPEED + else: + if a: + speed -= 1 + if b: + speed += 1 + + speed = min(255, max(1, speed)) + + offset += float(speed) / 2000.0 + for i in range(NUM_LEDS): - led_strip.set_hsv(i, t + (i / NUM_LEDS)) + hue = float(i) / NUM_LEDS + led_strip.set_hsv(i, hue + offset, 1.0, 1.0) + + led.set_rgb(speed, 0, 255 - speed) count += 1 if count >= UPDATES: From 33dcdd2e22be422f6f98eb7f8f576f68a42fb25b Mon Sep 17 00:00:00 2001 From: ZodiusInfuser Date: Wed, 18 Aug 2021 12:19:10 +0100 Subject: [PATCH 10/10] Tweak to rotary, for consistency --- examples/plasma_2040/plasma2040_rotary.cmake | 7 ++++--- examples/plasma_2040/plasma2040_rotary.cpp | 7 +++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/examples/plasma_2040/plasma2040_rotary.cmake b/examples/plasma_2040/plasma2040_rotary.cmake index 5dfc7087..a9a63214 100644 --- a/examples/plasma_2040/plasma2040_rotary.cmake +++ b/examples/plasma_2040/plasma2040_rotary.cmake @@ -1,6 +1,7 @@ -add_executable(plasma2040_rotary plasma2040_rotary.cpp) +set(OUTPUT_NAME plasma2040_rotary) +add_executable(${OUTPUT_NAME} plasma2040_rotary.cpp) -target_link_libraries(plasma2040_rotary +target_link_libraries(${OUTPUT_NAME} pico_stdlib plasma2040 breakout_encoder @@ -9,4 +10,4 @@ target_link_libraries(plasma2040_rotary button ) -pico_add_extra_outputs(plasma2040_rotary) +pico_add_extra_outputs(${OUTPUT_NAME}) diff --git a/examples/plasma_2040/plasma2040_rotary.cpp b/examples/plasma_2040/plasma2040_rotary.cpp index 650491d4..260ef9a6 100644 --- a/examples/plasma_2040/plasma2040_rotary.cpp +++ b/examples/plasma_2040/plasma2040_rotary.cpp @@ -16,6 +16,9 @@ using namespace pimoroni; // Set how many LEDs you have const uint N_LEDS = 30; +// How many times the LEDs will be updated per second +const uint UPDATES = 60; + // Pick *one* LED type by uncommenting the relevant line below: // APA102-style LEDs with Data/Clock lines. AKA DotStar @@ -67,7 +70,7 @@ void gauge(uint v, uint vmax = 100) { int main() { stdio_init_all(); - led_strip.start(60); + led_strip.start(UPDATES); bool encoder_detected = enc.init(); enc.clear_interrupt_flag(); @@ -147,6 +150,6 @@ int main() { // Sleep time controls the rate at which the LED buffer is updated // but *not* the actual framerate at which the buffer is sent to the LEDs - sleep_ms(1000 / 60); + sleep_ms(1000 / UPDATES); } }