Hello,
I am using the library from Elco Jacobs to control 8 RGB LEDs.
(ShiftPWM_Non_Blocking fromShiftPWM: the easiest software PWM library for Arduino | ElcoJacobs.com)
The sketch is awesome. It includ es 9 different modes for the LEDs and uses Serial.parseInt() to set the mode.
I built up the circuit on a perf board and want the whole system to be controlled by just 1 push button. I want the program to start when plugged in and stay in the first mode and switch to the second mode when the push button is pressed. Then, when pressed again, move to the 3rd mode then 4th ect.
I feel like this should be easy but I'm new to this stuff and I cannot find any help anywhere on this!
Thanks for any and all help.
/////This is the part of the sketch that selects the mode
void setup(){
while(!Serial){
delay(100);
}
Serial.begin(9600);
// Sets the number of 8-bit registers that are used.
ShiftPWM.SetAmountOfRegisters(numRegisters);
// SetPinGrouping allows flexibility in LED setup.
// If your LED's are connected like this: RRRRGGGGBBBBRRRRGGGGBBBB, use SetPinGrouping(4).
ShiftPWM.SetPinGrouping(1); //This is the default, but I added here to demonstrate how to use the funtion
ShiftPWM.Start(pwmFrequency,maxBrightness);
printInstructions();
}
void loop()
{
if(Serial.available()){
if(Serial.peek() == 'l'){
// Print information about the interrupt frequency, duration and load on your program
ShiftPWM.PrintInterruptLoad();
}
else if(Serial.peek() == 'm'){
// Print instructions again
printInstructions();
}
else{
fadingMode = Serial.parseInt(); // read a number from the serial port to set the mode
Serial.print("Mode set to ");
Serial.print(fadingMode);
Serial.print(": ");
startTime = millis();
switch(fadingMode){
case 0:
Serial.println("All LED's off");
break;
case 1:
Serial.println("Fade in and out one by one");
break;
case 2:
Serial.println("Fade in and out all LED's");
break;
case 3:
Serial.println("Fade in and out 2 LED's in parallel");
break;
case 4:
Serial.println("Alternating LED's in 6 different colors");
break;
case 5:
Serial.println("Hue shift all LED's");
break;
case 6:
Serial.println("Setting random LED's to random color");
break;
case 7:
Serial.println("Fake a VU meter");
break;
case 8:
Serial.println("Display a color shifting rainbow as wide as the LED's");
break;
case 9:
Serial.println("Display a color shifting rainbow wider than the LED's");
break;
default:
Serial.println("Unknown mode!");
break;
}
}
while (Serial.read() >= 0){
; // flush remaining characters
}
}
switch(fadingMode){
case 0:
// Turn all LED's off.
ShiftPWM.SetAll(0);
break;
case 1:
oneByOne();
break;
case 2:
inOutAll();
break;
case 3:
inOutTwoLeds();
break;
case 4:
alternatingColors();
break;
case 5:
hueShiftAll();
break;
case 6:
randomColors();
break;
case 7:
fakeVuMeter();
break;
case 8:
rgbLedRainbow(3000,numRGBLeds);
break;
case 9:
rgbLedRainbow(10000,5*numRGBLeds);
break;
default:
Serial.println("Unknown Mode!");
delay(1000);
break;
}
}