Hi all,
I have a single push button and an led shield. I have the following code which works but not as smoothly as it should. I would like the cases specified in the loop to happen in a cycle each time the button is pressed it should move to the next case. Case 1 and 3 are a steady color while case 2 and 4 require a loop to alternate between a color and nothing. Is there a better way to do this with an interrupt? I know I can't use the delay function in an interrupt function so I am not sure how I would perform the alternating writes in case 2 and 4. Any ideas?
Thank you

!
#include <Wire.h>
#include <HPRGB.h>
#include <Bounce.h>
HPRGB ledShield; //initialize
#define BUTTON 2 //button
//debouncer
Bounce bouncer = Bounce( BUTTON,5 );
int count = 0; //need a counter
void setup()
{
pinMode(BUTTON,INPUT); //initialize
Serial.begin(9600); //used for debugging
ledShield.begin(); //mA of each output
ledShield.setCurrent(350,350,350);
ledShield.setFreq(600); //set freq
ledShield.stopScript(); //stop check sequence
ledShield.eepromWrite(); //writes settings
delay(100); //needs this per spec
}
void loop()
{
bouncer.update ( ); //check and read
int value = bouncer.read();
if (value == HIGH) {
Serial.println("HIGH");
delay(500);
count = count + 1; //increment
int valuein = LOW; //used for c2 and c4
switch (count) {
case 1:
Serial.println("Pressed 1");
ledShield.goToRGB(0,0,255);
delay(1000);
break;
case 2:
Serial.println("Pressed 2");
while(valuein == LOW){
ledShield.goToRGB(0,0,255);
delay(1000);
ledShield.goToRGB(0,0,0);
delay(1000);
bouncer.update ( );
valuein = bouncer.read();
}
break;
case 3:
Serial.println("Pressed 3");
ledShield.goToRGB(255,0,0);
delay(1000);
break;
case 4:
Serial.println("Pressed 4");
while(valuein == LOW){
ledShield.goToRGB(255,0,0);
delay(1000);
ledShield.goToRGB(0,0,0);
delay(1000);
bouncer.update ( );
valuein = bouncer.read();
}
break;
}
if (count == 4) {
count = 0;
}
}
}