add hsv2rgb; rainbow puke should work now
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
#include <Arduino.h>
|
||||
#include "rgbled.h"
|
||||
|
||||
#include "hsv2rgb.h"
|
||||
|
||||
|
||||
|
||||
tinyNeoPixel rgb = tinyNeoPixel(RGB_COUNT, PIN_PA1, NEO_GRB, rgbled);
|
||||
|
||||
|
||||
|
||||
uint8_t rgbp_rainbow(uint8_t init);
|
||||
@@ -43,9 +49,11 @@ ISR(TCB0_INT_vect)
|
||||
|
||||
|
||||
// rgb program 0: rainbow puke
|
||||
#define RAINBOW_HUE_INC 50
|
||||
#define RAINBOW_OFFSET (1536/5)
|
||||
#define RAINBOW_TIMEOUT 240
|
||||
#define RAINBOW_HUE_INC 40 // how much to increment the hue every frame
|
||||
#define RAINBOW_OFFSET (1536/5) // offset between each LED
|
||||
#define RAINBOW_TIMEOUT 240 // how long to show this program
|
||||
#define RAINBOW_SAT 0xff // saturation
|
||||
#define RAINBOW_VAL 0x40 // value (brightness); keep low enough to keep average current down
|
||||
|
||||
uint16_t rainbow_hue = 0;
|
||||
uint16_t rainbow_timeout;
|
||||
@@ -53,24 +61,33 @@ uint16_t rainbow_timeout;
|
||||
uint8_t rgbp_rainbow(uint8_t init)
|
||||
{
|
||||
uint8_t i;
|
||||
uint8_t r, g, b;
|
||||
uint16_t hue;
|
||||
|
||||
// set our timer when initializing. otherwise every call is identical
|
||||
if (init) {
|
||||
rainbow_timeout = RAINBOW_TIMEOUT;
|
||||
}
|
||||
|
||||
if (--rainbow_timeout) {
|
||||
hue = rainbow_hue;
|
||||
// copy stored hue to working hue
|
||||
hue = rainbow_hue;
|
||||
|
||||
for (i = 0; i < RGB_COUNT; i++) {
|
||||
hue += RAINBOW_OFFSET;
|
||||
if (hue >= 1536) hue -= 1536;
|
||||
// each LED will increment its hue
|
||||
hue += RAINBOW_OFFSET;
|
||||
|
||||
// hue wheel is 256*6 large, so bound the value
|
||||
if (hue >= 1536) hue -= 1536;
|
||||
|
||||
// apply color
|
||||
// TODO
|
||||
// compute rgb from hue/sat/value
|
||||
hsv2rgb(hue, RAINBOW_SAT, RAINBOW_VAL, &r, &g, &b);
|
||||
|
||||
// apply it to this LED
|
||||
rgb.setPixelColor(i, r, g, b);
|
||||
}
|
||||
|
||||
// move the hue wheel for the next cycle through the program
|
||||
// increment stored hue wheel for the next cycle through the program
|
||||
rainbow_hue += RAINBOW_HUE_INC;
|
||||
if (rainbow_hue > 1536) rainbow_hue -= 1536;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user