I'm working on a simple program that uses 2 potentiometers, 2 push buttons, 2 RGB LEDs, and 1 buzzer. The basic idea is to use 1 potentiometer and 1 button to select the color to display on the LEDs and the other potentiometer and button to select the tone to sound the buzzer. Here is my code let me know what you think is going wrong:
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_NeoPixel.h> // include the Neopixel Library in this Sketch
#include <ezButton.h>
#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);
ezButton button1(7); // create ezButton object that attach to pin 7;
ezButton button2(9); // create ezButton object that attach to pin 9;
#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
};
void setup() {
// put your setup code here, to run once:
button1.setDebounceTime(50); // set debounce time to 50 milliseconds
button2.setDebounceTime(50); // set debounce time to 50 milliseconds
pinMode(BUZZER_PIN, 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() {
button1.loop(); // MUST call the loop() function first
button2.loop(); // MUST call the loop() function first
if (button1.isPressed()) {
BUTTON_PRESSED = true;
}
if (button1.isReleased()) {
BUTTON_PRESSED = false;
}
if (button2.isPressed()) {
BUTTON_PRESSED2 = true;
}
if (button2.isReleased()) {
BUTTON_PRESSED2 = false;
}
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){
// tone(BUZZER_PIN, NOTE_DS8);
// iterate over the notes of the melody:
for (int thisNote = 0; thisNote < 24; thisNote++) {
// to calculate the note duration, take one second divided by the note type.
//e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
int noteDuration = 1000 / noteDurations[thisNote];
tone(BUZZER_PIN, melody[thisNote], noteDuration);
// to distinguish the notes, set a minimum time between them.
// the note's duration + 30% seems to work well:
int pauseBetweenNotes = noteDuration * 1.30;
delay(pauseBetweenNotes);
// stop the tone playing:
noTone(BUZZER_PIN);
}
}else{
noTone(BUZZER_PIN);
}
}
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();
}
}
}
void rainbow(int wait) {
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this loop:
for(long firstPixelHue = 5*65536; firstPixelHue > 0; firstPixelHue -= 256) {
// strip.rainbow() can take a single argument (first pixel hue) or
// optionally a few extras: number of rainbow repetitions (default 1),
// saturation and value (brightness) (both 0-255, similar to the
// ColorHSV() function, default 255), and a true/false flag for whether
// to apply gamma correction to provide 'truer' colors (default true).
pxl.rainbow(firstPixelHue);
pxl2.rainbow(firstPixelHue);
// Above line is equivalent to:
// strip.rainbow(firstPixelHue, 1, 255, 255, true);
pxl.show(); // Update strip with new contents
pxl2.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}