#include <EEPROM.h>
#define RED 3
#define GREEN 5
#define BLUE 6
#define Button 4
#define Button2 8
int lastButtonState = 1;
long unsigned int lastPress;
int debounceTime = 20;
int counter;
int maxcounter = 7;
int state = 0;
void setup() {
// put your setup code here, to run once:
pinMode(RED, OUTPUT);
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(Button, INPUT_PULLUP);
counter = EEPROM.read(0);
counter = 0;
}
void loop() {
int buttonState = digitalRead(Button);
if((millis() - lastPress) > debounceTime)
{
lastPress = millis();
if(buttonState == 0 && lastButtonState == 1)
{
if(counter == maxcounter)
{
counter = 0;
EEPROM.write(0, counter);
}
counter++;
EEPROM.write(0, counter);
state = counter;
if(state == 1){off();}
if(state == 2){red();}
if(state == 3){green();}
if(state == 4){blue();}
if(state == 5){azure();}
if(state == 6){azure2();}
if(state == 7){azure3();}
lastButtonState = 0;
}
if(buttonState == 1 && lastButtonState == 0)
{
lastButtonState = 1;
}
}
}
//1
void off(){
analogWrite(GREEN,0);
analogWrite(RED,0);
analogWrite(BLUE,0);
}
//2
void red(){
analogWrite(GREEN,0);
analogWrite(RED,255);
analogWrite(BLUE,0);
}
//3
void green(){
analogWrite(GREEN,255);
analogWrite(RED,0);
analogWrite(BLUE,0);
}
//4
void blue(){
analogWrite(GREEN,0);
analogWrite(RED,0);
analogWrite(BLUE,255);
}
//5
void azure(){
analogWrite(GREEN,128);
analogWrite(RED,0);
analogWrite(BLUE,255);
}
//6
void azure2(){
analogWrite(GREEN,255);
analogWrite(RED,0);
analogWrite(BLUE,255);
}
//7
void azure3(){
analogWrite(GREEN,255);
analogWrite(RED,0);
analogWrite(BLUE,128);
}