So I have a program that tells you to pick the right or left button. The right button (but2) will rapidly change between colors and display the text "rainbow seizure" on the LCD. I would like the other button to have every time you press it, it changes a color (the colors that I used for the rainbow) and displays that colors name on the LCD and every time you press the button it changes to the next solid color. Not sure how to code it so it will switch every time you press the button to a new color and then when you get to aqua it will go back to red.
Thanks for trying to help!
#include <LiquidCrystal.h>
const int but1 = 1;
const int but2 = 2;
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int buttonState1 = 0;
int buttonState2 = 0;
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
#define COMMON_ANODE
void setup() {
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
setColor(0, 0, 0);
lcd.begin(16, 2);
pinMode(but1, INPUT);
pinMode(but2, INPUT);
lcd.setCursor(0,0);
lcd.print("Left for change");
lcd.setCursor(0,1);
lcd.print("Right for fast");
lcd.display();
}
void loop() {
buttonState1 = digitalRead(but1);
buttonState2 = digitalRead(but2);
while (buttonState2 == HIGH)
{
lcd.clear();
lcd.print("Rainbow Seizure");
lcd.display();
setColor(255, 0, 0); // red
delay(70);
setColor(0, 255, 0); // green
delay(70);
setColor(0, 0, 255); // blue
delay(70);
setColor(255, 255, 0); // yellow
delay(70);
setColor(80, 0, 80); // purple
delay(70);
setColor(0, 255, 255); // aqua
delay(70);
}
// ***** Here is where I want to be able to press my but1 (buttonState1) to be able to be pressed multiple times and switch to each one of the
// ***** colors above and have the name of the color displayed on the lcd
}
void setColor(int red, int green, int blue)
{
#ifdef COMMON_ANODE
red = 255 - red;
green = 255 - green;
blue = 255 - blue;
#endif
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}