Hi, Ive been trying to work on a project for the past few weeks and previously asked some questions Is it possible to have a simultaneous button press to turn on a LED - Programming Questions - Arduino Forum, before realising the solution that I was creating did not work as I thought it would and going back to the drawing board.
However despite restarting I've now become a little bit stuck again and would like to ask some for some advice and also particualarly whether its feasible to do something I would like to do or whether I need to find a new solution.
I am still really new to this, and have to apologies if my current code (below) is not as good as it should be:
const int push_white=2;
const int push_green=3;
const int push_red=4;
const int push_blue=5;
const int led_green=9;
const int led_red=10;
const int led_blue=11;
const int led_white=12;
const long BLINK_INTERVAL = 1000;
int state_green=false;
int state_red=false;
int state_blue=false;
int state_white=false;
unsigned long previousMillis = 0;
void setup() {
pinMode(push_white, INPUT);
pinMode(push_green, INPUT);
pinMode(push_red, INPUT);
pinMode(push_blue, INPUT);
pinMode(led_green, OUTPUT);
pinMode(led_red, OUTPUT);
pinMode(led_blue, OUTPUT);
pinMode(led_white, OUTPUT);
Serial.begin(9600);
}
void loop() {
clean();
state_green=digitalRead(push_green);
state_red=digitalRead(push_red);
state_blue=digitalRead(push_blue);
state_white=digitalRead(push_white);
if(state_white==true)
{
clean();
digitalWrite(led_white, HIGH);
Serial.print("White");
Serial.print("\n");
}
if(state_green==true)
{
clean();
digitalWrite(led_green, LOW);
digitalWrite(led_blue, LOW);
digitalWrite(led_red, LOW);
Serial.print("ALL OFF");
Serial.print("\n");
}
if(state_red==true)
{
clean();
digitalWrite(led_green, LOW);
digitalWrite(led_red, HIGH);
Serial.print("Red");
Serial.print("\n");
}
if(state_blue==true)
{
clean();
digitalWrite(led_red, HIGH);
digitalWrite(led_green, HIGH);
Serial.print("Orange On");
Serial.print("\n");
delay(750);
digitalWrite(led_red, LOW);
digitalWrite(led_green, LOW);
Serial.print("Orange Off");
Serial.print("\n");
}
if(state_white==true && state_green==true)
{
clean();
digitalWrite(led_white, HIGH);
digitalWrite(led_green, HIGH);
Serial.print("Green");
Serial.print("\n");
}
}
void clean(){
digitalWrite(led_white, LOW);
}
I've been racking my brain and failing miserably, so I thought I'd ask for some advice in case its not feasible to do what I had hope and I should try and find an alternative.
Where I have been struggling is in an attempt to add a double press to my code. Where this differs from other examples I had tried to work from is that they seem to focus on making a single button multi functional.
What I would like to actually implement involves a state of two buttons rather than one, this would be similar to the last state above (White and Green).
The new action will still involve the white button (be held down), but I would like to activate a blue led if the green button was be double pressed/tapped in quick succession, rather than just a single press (which should activate the green light). On its own the Green button currently stops all leds.
Having gone round in circles can I please ask whether if this is something that is actually possible to implement? If so, please can you advise of any suggestions, examples or topics I should explore. Alternatively I am happy to take suggestions of alternative solutions.
(Please note, theres some code within my code that I am still working and its not yet - i.e. blink, as I would also like to make the 'state_red" flash the LED rather than stay on), but have not yet got that working either, as my focus has primarily been on the above issue).