/*
Neopixel Colour Wheel
Aug 18 2024
Version 001
by trulyBent, Public Domain
I don't know how this Neopixel wheel was built, but I found it
here: https://wokwi.com/projects/406466798528780289?gh=1
I had to rewrite the code, including finding the wheel() function
(https://forum.arduino.cc/t/wheel-was-not-declared-in-scope/478906/10)
*/
#include <Adafruit_NeoPixel.h>
int PIN = 12;
int N_LEDS = 40;
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_LEDS, PIN);
////////////////////////////////////////////////////////////
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
////////////////////////////////////////////////////////////
void setup() {
strip.begin();
}
////////////////////////////////////////////////////////////
void loop() {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, wheel((i + j) & 255));
}
strip.show();
delay(100);
}
}