2021-07-16 17:01:55 +01:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <cstdint>
|
|
|
|
|
|
|
|
#include "pico/stdlib.h"
|
|
|
|
|
|
|
|
#include "plasma2040.hpp"
|
|
|
|
|
|
|
|
#include "common/pimoroni_common.hpp"
|
|
|
|
#include "rgbled.hpp"
|
|
|
|
#include "button.hpp"
|
|
|
|
|
|
|
|
/*
|
|
|
|
Press "B" to speed up the LED cycling effect.
|
|
|
|
Press "A" to slow it down again.
|
2021-08-18 10:54:31 +01:00
|
|
|
Press "Boot" to reset the speed back to default.
|
2021-07-16 17:01:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
using namespace pimoroni;
|
|
|
|
|
|
|
|
// Set how many LEDs you have
|
|
|
|
const uint N_LEDS = 30;
|
|
|
|
|
2021-08-18 10:54:31 +01:00
|
|
|
// 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;
|
|
|
|
|
2021-07-16 17:01:55 +01:00
|
|
|
// Pick *one* LED type by uncommenting the relevant line below:
|
|
|
|
|
|
|
|
// APA102-style LEDs with Data/Clock lines. AKA DotStar
|
|
|
|
//plasma::APA102 led_strip(N_LEDS, pio0, 0, plasma::PIN_DAT, plasma::PIN_CLK);
|
|
|
|
|
|
|
|
// WS28X-style LEDs with a single signal line. AKA NeoPixel
|
2021-08-02 12:33:20 +01:00
|
|
|
// by default the WS2812 LED strip will be 400KHz, RGB with no white element
|
2021-07-16 17:01:55 +01:00
|
|
|
plasma::WS2812 led_strip(N_LEDS, pio0, 0, plasma::PIN_DAT);
|
|
|
|
|
2021-08-18 10:54:31 +01:00
|
|
|
Button user_sw(plasma::USER_SW, Polarity::ACTIVE_LOW, 0);
|
2021-07-16 17:01:55 +01:00
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
stdio_init_all();
|
|
|
|
|
2021-08-18 10:54:31 +01:00
|
|
|
led_strip.start(UPDATES);
|
2021-07-16 17:01:55 +01:00
|
|
|
|
2021-08-18 10:54:31 +01:00
|
|
|
int speed = DEFAULT_SPEED;
|
2021-07-16 17:01:55 +01:00
|
|
|
float offset = 0.0f;
|
|
|
|
|
|
|
|
while (true) {
|
2021-08-18 10:54:31 +01:00
|
|
|
bool sw = user_sw.read();
|
2021-07-16 17:01:55 +01:00
|
|
|
bool a = button_a.read();
|
|
|
|
bool b = button_b.read();
|
2021-08-18 10:54:31 +01:00
|
|
|
|
|
|
|
if(sw) {
|
|
|
|
speed = DEFAULT_SPEED;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(a) speed--;
|
|
|
|
if(b) speed++;
|
|
|
|
}
|
2021-07-16 17:01:55 +01:00
|
|
|
speed = std::min((int)255, std::max((int)1, speed));
|
|
|
|
|
|
|
|
offset += float(speed) / 2000.0f;
|
|
|
|
|
|
|
|
for(auto i = 0u; i < led_strip.num_leds; ++i) {
|
|
|
|
float hue = float(i) / led_strip.num_leds;
|
|
|
|
led_strip.set_hsv(i, hue + offset, 1.0f, 1.0f);
|
|
|
|
}
|
|
|
|
|
|
|
|
led.set_rgb(speed, 0, 255 - speed);
|
|
|
|
|
|
|
|
// 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
|
2021-08-18 10:54:31 +01:00
|
|
|
sleep_ms(1000 / UPDATES);
|
2021-07-16 17:01:55 +01:00
|
|
|
}
|
|
|
|
}
|