/*
https://forum.arduino.cc/t/working-on-a-project-with-2-potentiometers-2-push-buttons-2-leds-and-1-buzzer/1387619
*/
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h> // include the Neopixel Library in this Sketch
//TO DO: 1st, add the second LED DONE
//2nd, add the second push button DONE
//3rd, add the second potentiometer DONE
//4th, add the logic for the speaker DONE
#define PIN 3 // This is the Arduino Pin controlling the LED pixel.
#define PIN2 5 // This is the Arduino Pin controlling the other LED pixel.
#define POTENTIOMETER_PIN A0
#define POTENTIOMETER_PIN2 A2
#define BUZZER_PIN 11
//This sketch is to make a potentiometer position determine a color of a LED
// that shows when a button is pressed
//If possible, another potentiometer to determine tone
#define NUMPIXELS 1
#define BRIGHTNESS 50
Adafruit_NeoPixel pxl = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800);
Adafruit_NeoPixel pxl2 = Adafruit_NeoPixel(NUMPIXELS, PIN2, NEO_GRBW + NEO_KHZ800);
#define PUSH_BUTTON 9
#define PUSH_BUTTON2 7
#define REST 0
#define NOTE_B0 31
#define NOTE_C1 33
#define NOTE_CS1 35
#define NOTE_D1 37
#define NOTE_DS1 39
#define NOTE_E1 41
#define NOTE_F1 44
#define NOTE_FS1 46
#define NOTE_G1 49
#define NOTE_GS1 52
#define NOTE_A1 55
#define NOTE_AS1 58
#define NOTE_B1 62
#define NOTE_C2 65
#define NOTE_CS2 69
#define NOTE_D2 73
#define NOTE_DS2 78
#define NOTE_E2 82
#define NOTE_F2 87
#define NOTE_FS2 93
#define NOTE_G2 98
#define NOTE_GS2 104
#define NOTE_A2 110
#define NOTE_AS2 117
#define NOTE_B2 123
#define NOTE_C3 131
#define NOTE_CS3 139
#define NOTE_D3 147
#define NOTE_DS3 156
#define NOTE_E3 165
#define NOTE_F3 175
#define NOTE_FS3 185
#define NOTE_G3 196
#define NOTE_GS3 208
#define NOTE_A3 220
#define NOTE_AS3 233
#define NOTE_B3 247
#define NOTE_C4 262
#define NOTE_CS4 277
#define NOTE_D4 294
#define NOTE_DS4 311
#define NOTE_E4 330
#define NOTE_F4 349
#define NOTE_FS4 370
#define NOTE_G4 392
#define NOTE_GS4 415
#define NOTE_A4 440
#define NOTE_AS4 466
#define NOTE_B4 494
#define NOTE_C5 523
#define NOTE_CS5 554
#define NOTE_D5 587
#define NOTE_DS5 622
#define NOTE_E5 659
#define NOTE_F5 698
#define NOTE_FS5 740
#define NOTE_G5 784
#define NOTE_GS5 831
#define NOTE_A5 880
#define NOTE_AS5 932
#define NOTE_B5 988
#define NOTE_C6 1047
#define NOTE_CS6 1109
#define NOTE_D6 1175
#define NOTE_DS6 1245
#define NOTE_E6 1319
#define NOTE_F6 1397
#define NOTE_FS6 1480
#define NOTE_G6 1568
#define NOTE_GS6 1661
#define NOTE_A6 1760
#define NOTE_AS6 1865
#define NOTE_B6 1976
#define NOTE_C7 2093
#define NOTE_CS7 2217
#define NOTE_D7 2349
#define NOTE_DS7 2489
#define NOTE_E7 2637
#define NOTE_F7 2794
#define NOTE_FS7 2960
#define NOTE_G7 3136
#define NOTE_GS7 3322
#define NOTE_A7 3520
#define NOTE_AS7 3729
#define NOTE_B7 3951
#define NOTE_C8 4186
#define NOTE_CS8 4435
#define NOTE_D8 4699
#define NOTE_DS8 4978
//#define LED 4
int PXL1[] = {0};
int PXL2[] = {0};
bool BUTTON_PRESSED = false;
bool BUTTON_PRESSED2 = false;
int delayval = 50;
int melody[] = {
NOTE_E3, NOTE_DS3, NOTE_FS3, NOTE_E3, NOTE_G3, NOTE_FS3, NOTE_A3, NOTE_G3, NOTE_AS3, NOTE_B3, NOTE_E4, NOTE_E5, NOTE_DS5, NOTE_D5, NOTE_CS5, REST, NOTE_DS5, NOTE_D5, NOTE_CS5, NOTE_C5, REST, NOTE_FS5, NOTE_FS5, NOTE_E5
};
// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
2, 2, 2, 2, 3, 3, 2, 2, 2, 2, 3, 12, 12, 12, 1, 16, 12, 12, 12, 1, 16, 4, 2, 1
};
//vars for playMelody
int currNote = 0;
bool notePlaying = false;
unsigned long noteStart;
unsigned long noteDuration;
// now
unsigned long now;
//button debouncing vars..
unsigned long btn1Debounce;
unsigned long btn2Debounce;
unsigned long btnWait = 20;
//vars for rainbow
long pixelHue = 5 * 65536;
unsigned long lastPixelUpdate;
//non-blocking melody player..
void playMelody(){
if (now-noteStart >= noteDuration){
if (notePlaying){
notePlaying = false;
noteDuration = noteDuration * 1.30;
noTone(BUZZER_PIN);
noteStart = now;
currNote++;
if (currNote>23) currNote=0;
} else{
notePlaying = true;
noteDuration = 1000 / noteDurations[currNote];
tone(BUZZER_PIN,melody[currNote]);
noteStart = now;
}
}
}
void setup() {
// put your setup code here, to run once:
pinMode(BUZZER_PIN, OUTPUT);
pinMode(PUSH_BUTTON, INPUT_PULLUP);
pinMode(PUSH_BUTTON2, INPUT_PULLUP);
// pinMode(LED, OUTPUT);
pxl.begin();
pxl.show(); // Turn OFF all strip ASAP
pxl.setBrightness(BRIGHTNESS);
pxl2.begin();
pxl2.show(); // Turn OFF all strip ASAP
pxl2.setBrightness(BRIGHTNESS);
}
void loop() {
now = millis();
byte b;
if (now - btn1Debounce >= btnWait){
b = !digitalRead(PUSH_BUTTON);
if (b != BUTTON_PRESSED) {
BUTTON_PRESSED = b;
btn1Debounce = now;
}
}
if (now - btn2Debounce >= btnWait){
b = !digitalRead(PUSH_BUTTON2);
if (b != BUTTON_PRESSED2) {
BUTTON_PRESSED2 = b;
btn2Debounce = now;
}
}
int potentiometerValue = analogRead(POTENTIOMETER_PIN); //read the potentiometer
int percent = map(potentiometerValue, 0, 1023, 0, 100); //map the pot value to percent
int potentiometerValue2 = analogRead(POTENTIOMETER_PIN2); //read the potentiometer
int percent2 = map(potentiometerValue2, 0, 1023, 0, 100); //map the pot value to percent
if (percent2 >= 0 && percent2 <= 2) {
if (BUTTON_PRESSED2) {
//play tone
tone(BUZZER_PIN, NOTE_B0);
} else {
//play no tone
noTone(BUZZER_PIN);
}
} else if (percent2 > 2 && percent2 < 4) {
//draw2();
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 3 && percent2 < 5) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 4 && percent2 < 6) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 5 && percent2 < 7) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 6 && percent2 < 8) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_E1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 7 && percent2 < 9) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_F1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 8 && percent2 < 10) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_FS1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 9 && percent2 < 11) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_G1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 10 && percent2 < 12) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_GS1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 11 && percent2 < 13) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_A1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 12 && percent2 < 14) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_AS1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 13 && percent2 < 15) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_B1);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 14 && percent2 < 16) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 15 && percent2 < 17) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 16 && percent2 < 18) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 17 && percent2 < 19) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 18 && percent2 < 20) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_E2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 19 && percent2 < 21) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_F2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 20 && percent2 < 22) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_FS2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 21 && percent2 < 23) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_G2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 22 && percent2 < 24) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_GS2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 23 && percent2 < 25) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_A2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 24 && percent2 < 26) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_AS2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 25 && percent2 < 27) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_B2);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 26 && percent2 < 28) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 27 && percent2 < 29) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 28 && percent2 < 30) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 29 && percent2 < 31) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 30 && percent2 < 32) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_E3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 31 && percent2 < 33) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_F3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 32 && percent2 < 34) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_FS3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 33 && percent2 < 35) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_G3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 34 && percent2 < 36) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_GS3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 35 && percent2 < 37) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_A3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 36 && percent2 < 38) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_AS3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 37 && percent2 < 39) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_B3);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 38 && percent2 < 40) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 39 && percent2 < 41) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 40 && percent2 < 42) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 41 && percent2 < 43) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 42 && percent2 < 44) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_E4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 43 && percent2 < 45) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_F4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 44 && percent2 < 46) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_FS4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 45 && percent2 < 47) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_G4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 46 && percent2 < 48) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_GS4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 47 && percent2 < 49) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_A4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 48 && percent2 < 50) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_AS4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 49 && percent2 < 51) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_B4);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 50 && percent2 < 52) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 51 && percent2 < 53) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 52 && percent2 < 54) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 53 && percent2 < 55) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 54 && percent2 < 56) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_E5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 55 && percent2 < 57) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_F5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 56 && percent2 < 58) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_FS5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 57 && percent2 < 59) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_G5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 58 && percent2 < 60) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_GS5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 59 && percent2 < 61) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_A5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 60 && percent2 < 62) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_AS5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 61 && percent2 < 63) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_B5);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 62 && percent2 < 64) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 63 && percent2 < 65) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 64 && percent2 < 66) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 65 && percent2 < 67) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 66 && percent2 < 68) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_E6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 67 && percent2 < 69) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_F6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 68 && percent2 < 70) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_FS6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 69 && percent2 < 71) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_G6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 70 && percent2 < 72) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_GS6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 71 && percent2 < 73) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_A6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 72 && percent2 < 74) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_AS6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 73 && percent2 < 75) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_B6);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 74 && percent2 < 76) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 75 && percent2 < 77) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 76 && percent2 < 78) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 77 && percent2 < 79) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 78 && percent2 < 80) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_E7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 79 && percent2 < 81) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_F7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 80 && percent2 < 82) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_FS7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 81 && percent2 < 83) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_G7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 82 && percent2 < 84) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_GS7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 83 && percent2 < 85) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_A7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 84 && percent2 < 86) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_AS7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 85 && percent2 < 87) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_B7);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 86 && percent2 < 88) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_C8);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 87 && percent2 < 89) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_CS8);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 88 && percent2 < 90) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_D8);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 89 && percent2 < 91) {
if (BUTTON_PRESSED2) {
tone(BUZZER_PIN, NOTE_DS8);
} else {
noTone(BUZZER_PIN);
}
} else if (percent2 > 90 && percent2 <= 100) {
if (BUTTON_PRESSED2) {
playMelody();
} else {
noTone(BUZZER_PIN);
//reset melody vars
currNote = 0;
notePlaying = false;
}
}
if (percent >= 0 && percent <= 8) { //between 0 and 4
//draw1();
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 255));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 255));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 9 && percent <= 16) {
//draw2();
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(128, 0, 255));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(128, 0, 255));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 17 && percent <= 24) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(255, 0, 255));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(255, 0, 255));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 25 && percent <= 32) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(255, 0, 128));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(255, 0, 128));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 33 && percent <= 40) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(255, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(255, 0, 0));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 41 && percent <= 48) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(255, 128, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(255, 128, 0));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 49 && percent <= 56) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(255, 255, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(255, 255, 0));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 57 && percent <= 64) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(128, 255, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(128, 255, 0));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 65 && percent <= 72) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(0, 255, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 255, 0));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 73 && percent <= 80) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(0, 255, 128));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 255, 128));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 81 && percent <= 88) {
if (BUTTON_PRESSED) {
//create variables to store color values
//write a line that
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(0, 255, 255));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 255, 255));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 89 && percent <= 95) {
if (BUTTON_PRESSED) {
//create variables to store color values
//then write a line that tells the LED to shine or "show"
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(0, 128, 255));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 128, 255));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 96 && percent <= 98) {
if (BUTTON_PRESSED) {
//create variables to store color values
//then write a line that tells the LED to shine or "show"
//digitalWrite(LED, HIGH); //LED ON
pxl.setPixelColor(PXL1[0], pxl.Color(255, 255, 255));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(255, 255, 255));
pxl2.show();
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
}
} else if (percent >= 99 && percent <= 100) {
if (BUTTON_PRESSED) {
rainbow(4);
// rainbow2(4);
} else {
//digitalWrite(LED, LOW); //LED OFF
pxl.setPixelColor(PXL1[0], pxl.Color(0, 0, 0));
pxl.show();
pxl2.setPixelColor(PXL2[0], pxl2.Color(0, 0, 0));
pxl2.show();
//reset rainbow var..
pixelHue = 5 * 65536;
}
}
}
void rainbow(int wait) {
if (now - lastPixelUpdate >= wait){
pxl.rainbow(pixelHue);
pxl2.rainbow(pixelHue);
pxl.show(); // Update strip with new contents
pxl2.show(); // Update strip with new contents
if (pixelHue > 255){
pixelHue -= 256;
} else{
pixelHue = 5 * 65536;
}
lastPixelUpdate = now;
}
}