#include <Adafruit_NeoPixel.h>
#include "GlowingPixels.cpp"
#define NUMPIXELS 12
#define CHANGE_DELAY 16
const uint32_t RED = Adafruit_NeoPixel::Color(255, 0, 0);
const uint32_t GREEN = Adafruit_NeoPixel::Color(0, 255, 0);
const uint32_t BLUE = Adafruit_NeoPixel::Color(0, 0, 255);
struct pin_mapping {
int button;
int neo;
uint32_t colour;
};
const pin_mapping pinMapping[] = {
{12, 25, RED},
{11, 27, BLUE},
{10, 29, GREEN},
{9, 31, RED}
};
const int connectionNum = sizeof(pinMapping)/sizeof(*pinMapping);
struct pixel_connection {
GlowingPixels pixel;
int buttonPin;
} pixels[connectionNum];
void update() {
for (int i = 0; i < connectionNum; i++) {
int buttonPressed = digitalRead(pixels[i].buttonPin);
if (buttonPressed == LOW) {
pixels[i].pixel.update();
}
}
}
void draw() {
for (int i = 0; i < connectionNum; i++) {
int buttonPressed = digitalRead(pixels[i].buttonPin);
if (buttonPressed == LOW) {
pixels[i].pixel.draw();
} else {
pixels[i].pixel.clear();
}
}
}
void setup() {
Serial.begin(115200);
for (int i = 0; i < connectionNum; i++) {
pixels[i].pixel = GlowingPixels(pinMapping[i].neo, pinMapping[i].colour);
pixels[i].buttonPin = pinMapping[i].button;
pixels[i].pixel.begin();
pinMode(pixels[i].buttonPin, INPUT_PULLUP);
}
}
void loop() {
update();
draw();
delay(CHANGE_DELAY);
}