Skip to content

Commit

Permalink
fill in rainbow function
Browse files Browse the repository at this point in the history
  • Loading branch information
LucienMorey committed Nov 21, 2023
1 parent 1f14c8d commit 435ce18
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion wsce_display_bot.ino
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,25 @@ constexpr auto TILT_LOWER_LIMIT_PIN = 6U;
// This is a value in the range (0,1]

/* LED routines */
void rainbow(const double phase, Adafruit_NeoPixel *leds) {}
void rainbow(const double phase, Adafruit_NeoPixel *leds)
{

double rainbow_phase = 20 * phase;
rainbow_phase = rainbow_phase - (int)rainbow_phase;
const double resolution = 1.0 / leds->numPixels();

for (int i = 0; i < leds->numPixels(); i++)
{
// remap phased hue to be within 0 and 1
double hue_scale = (i * resolution + rainbow_phase);
hue_scale = hue_scale - (int)hue_scale;

// scale and set hue
long pixel_hue = 65535 * hue_scale;
leds->setPixelColor(i, leds->gamma32(leds->ColorHSV(pixel_hue)));
}
leds->show();
}

/* Motor routines */

Expand Down

0 comments on commit 435ce18

Please sign in to comment.