Sorry for not putting the code up, a lot of things where in my language :).
This part is for buttons,leds etc.. .It has some redudant lines
//Buttons
int send_R = 12;
int send_B = 11;
//rgb LED
int led1R = 10;
int led1B = 9;
int led2R = 8;
int led2B = 7;
int previusR = LOW;
int previousB = LOW;
int neutral = LOW;
long debounce = 200;
long dur_on = 0;
unsigned long previousMillis1 = 0;
unsigned long previousMillis2 = 0;
unsigned long previousMillis3 = 0;
int state = LOW;
int stateB = LOW;
int stateR = LOW;
unsigned long interval = 4;
unsigned long interval2 = 2;
unsigned long interval3 = 5;
unsigned long interval4 = 9;
long time = 0;
void setup() {
pinMode(send_R, INPUT);
pinMode(send_B, INPUT);
pinMode(led1R, OUTPUT);
pinMode(led1B, OUTPUT);
pinMode(led2R, OUTPUT);
pinMode(led2B, OUTPUT);
Serial.begin(9600);
}
Void loop
void loop() {
unsigned long currentMillis = millis();
int buttonR = digitalRead(send_R);
int buttonB = digitalRead(send_B);
dur_on = (millis() - time) / 1000;
if (buttonR == HIGH && previusR == LOW && millis() - time > debounce)
{
time = millis();
if (state == HIGH)
state = LOW;
else
state = HIGH;
}
if (buttonB == HIGH && previousB == LOW && millis() - time > debounce)
{
time = millis();
if (state == HIGH)
state = LOW;
else
state = HIGH;
}
So these part of the code is the deal breaker.
It goes like this:
- first, you need to hold the red button for 5-second or more. The red led goes on.
- then you need to hold the blue button for 5-seconds or more. Then the red light dies and the blue light lights up
- Now if you push the red button again the blue light flickers, dies then after 10 seconds it goes to re.
// using this to so that if the blue button was pressed after the red one it uses this IF for the red button, so that it takes you from blue to neutral to red
if ((buttonR == HIGH) && (millis() - time > debounce))
{
if ((stateB == LOW) && (dur_on >= interval)) {
digitalWrite(led2R, HIGH);
digitalWrite(led2B, LOW);
Serial.println("first led is on");
state == HIGH;
}
if ((stateB == HIGH) && (neutral == LOW)) {
if (dur_on <= interval) {
digitalWrite(led2B, HIGH);
delay(interval2);
digitalWrite(led2B, LOW);
Serial.println("losing blue led");
}
else if ((dur_on >= 5) && (dur_on <= 6)) {
digitalWrite(led2R, LOW);
digitalWrite(led2B, HIGH);
digitalWrite(led2B, LOW);
Serial.println("Neutral");
}
else if (dur_on >= interval4) {
digitalWrite(led2R, HIGH);
digitalWrite(led2B, LOW);
Serial.println("red led on");
}
}
}
This code is for the blue LED on if it meets the 5-second interval
if ((buttonB == HIGH) && (millis() - time > debounce))
{
if (dur_on >= interval) {
previousMillis2 = dur_on;
digitalWrite(led2B, HIGH);
digitalWrite(led2R, LOW);
stateB = HIGH;
stateR = HIGH;
Serial.println("Blue is on");
}
}
previusR = buttonR;
previousB = buttonB;
}