#include <Adafruit_NeoPixel.h>
#include "ColourKit.h"
int choose;
int Button1;
int Button2;
int Button3;
Adafruit_NeoPixel ledstrip(1, 3, NEO_GRB + NEO_KHZ800);
unsigned long lastChange = 0;
uint8_t hue = 0;
uint8_t colorIndex = 0; // 0–15
const uint8_t colors[16][3] = {
{255, 0, 0}, // 1 Red
{255, 80, 0}, // 2 Orange
{255, 255, 0}, // 3 Yellow
{120, 255, 0}, // 4 Lime
{ 0, 255, 0}, // 5 Green
{ 0, 255, 120}, // 6 Spring green
{ 0, 255, 255}, // 7 Cyan
{ 0, 120, 255}, // 8 Sky blue
{ 0, 0, 255}, // 9 Blue
{ 80, 0, 255}, // 10 Violet
{150, 0, 255}, // 11 Purple
{255, 0, 255}, // 12 Magenta
{255, 0, 120}, // 13 Pink
{255, 60, 60}, // 14 Rose
{255, 200, 120}, // 15 Warm white
{180, 200, 255} // 16 Cool white
};
void setup() {
ledstrip.begin();
choose = 3;
Button1 = 4;
pinMode(Button1, INPUT);
Button2 = 9;
pinMode(Button2, INPUT);
Button3 = 6;
pinMode(Button3, INPUT);
ledstrip.show();
}
void wheel(uint8_t pos, uint8_t &r, uint8_t &g, uint8_t &b) {
if (pos < 85) {
r = 255 - pos * 3;
g = pos * 3;
b = 0;
} else if (pos < 170) {
pos -= 85;
r = 0;
g = 255 - pos * 3;
b = pos * 3;
} else {
pos -= 170;
r = pos * 3;
g = 0;
b = 255 - pos * 3;
}
}
void RAINBOW(int DELAY) {
uint8_t r, g, b;
wheel(hue, r, g, b);
ledstrip.setPixelColor(0, Colour(r, g, b));
ledstrip.show();
hue++;
delay(DELAY);
}
void loop() {
if (choose == 0) {
unsigned long interval = map(analogRead(A0), 0, 1023, 100, 2000);
if (millis() - lastChange >= interval) {
lastChange = millis();
ledstrip.setPixelColor(
0,
Colour(
colors[colorIndex][0],
colors[colorIndex][1],
colors[colorIndex][2]
)
);
ledstrip.show();
colorIndex++;
if (colorIndex >= 16) {
colorIndex = 0; // back to 1
}
}
pinMode(Button3, INPUT);
if (digitalRead(Button1) == HIGH) {
choose = 0;
} else if (digitalRead(Button2) == HIGH) {
choose = 1;
} else if (digitalRead(Button3) == HIGH) {
choose = 2;
}
} else if (choose == 1) {
ledstrip.setPixelColor(1, Colour(255, 255, 255));
ledstrip.show();
ledstrip.show();
pinMode(Button3, INPUT);
if (digitalRead(Button1) == HIGH) {
choose = 0;
} else if (digitalRead(Button2) == HIGH) {
choose = 1;
} else if (digitalRead(Button3) == HIGH) {
choose = 2;
}
delay(20);
} else if (choose == 2) {
pinMode(Button3, INPUT);
if (digitalRead(Button1) == HIGH) {
choose = 0;
} else if (digitalRead(Button2) == HIGH) {
choose = 1;
} else if (digitalRead(Button3) == HIGH) {
choose = 2;
}
RAINBOW(map(analogRead(A0), 0, 1023, 1, 1000));
} else {
ledstrip.setPixelColor(1, 0x000000);
ledstrip.show();
pinMode(Button3, INPUT);
if (digitalRead(Button1) == HIGH) {
choose = 0;
} else if (digitalRead(Button2) == HIGH) {
choose = 1;
} else if (digitalRead(Button3) == HIGH) {
choose = 2;
}
}
}