#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel pixels(16, 10, NEO_GRB + NEO_KHZ800);
const int leds[] = {2, 3, 4, 5, 6, 7, 8, 9}; // LED pins
const int buttons[] = {A0, A1, A2, A3, A4}; // Button pins
const int delayTime = 750; // 80 BPM, adjust as needed
void setup() {
pixels.begin();
// Initialize LEDs as OUTPUT
for (int i = 0; i < 8; i++) {
pinMode(leds[i], OUTPUT);
}
// Initialize buttons as INPUT_PULLUP
for (int i = 0; i < 5; i++) {
pinMode(buttons[i], INPUT_PULLUP);
}
}
void loop() {
pixels.clear(); // Set all pixel colors to 'off'
// The first NeoPixel in a strand is #0, second is 1, all the way up
// to the count of pixels minus one.
for(int i=0; i< 16; i++) { // For each pixel...
// pixels.Color() takes RGB values, from 0,0,0 up to 255,255,255
// Here we're using a moderately bright green color:
pixels.setPixelColor(i, pixels.Color(i*16, 150, 255/(i+1)));
pixels.show(); // Send the updated pixel colors to the hardware.
delay(50); // Pause before next pass through loop
}
if (digitalRead(buttons[0]) == LOW) { // Active LOW due to INPUT_PULLUP
playA();
Serial.println("in A");
} else if (digitalRead(buttons[1]) == LOW) {
playM();
} else if (digitalRead(buttons[2]) == LOW) {
playR();
} else if (digitalRead(buttons[3]) == LOW) {
playK();
} else if (digitalRead(buttons[4]) == LOW) {
playE();
}
}
// Preset Functions
void playA() {
flashLeds(0, 8);
}
void playM() {
flashLeds(0, 3);
flashLeds(4, 8);
}
void playR() {
flashLeds(0, 3);
}
void playK() {
flashLeds(0, 5);
}
void playE() {
flashLeds(0, 5);
}
void flashLeds(int start, int end) {
for (int i = start; i < end; i++) {
digitalWrite(leds[i], HIGH);
}
delay(delayTime);
for (int i = start; i < end; i++) {
digitalWrite(leds[i], LOW);
}
// delay(delayTime);
}