PaulS:
Hi I'm trying to use your code to store the status of 4 leds, this is the message I receive when I verify it :
That code was a snippet, to define how to do a small task, not a complete sketch. Show your complete sketch.
Hi thanks for the reply, here is the sketch I'm using, with this sketch I can turn on/off one or more led and I would like to use the above mentioned code to store leds combination when another pushbutton (store) is pressed.
//pushbutton= pin
int Rosso_Button = 30;
int Giallo_Button = 31;
int Verde_Button = 32;
//pushbutton current state
int stato_bottoni[3];
boolean stato_switch[3];
// led = pin
int Led_Rosso = 11;
int Led_Giallo = 10;
int Led_Verde = 9;
void setup()
{
// pushbuttons
pinMode (Rosso_Button, INPUT);
pinMode (Giallo_Button, INPUT);
pinMode (Verde_Button, INPUT);
// Led
pinMode (Led_Rosso, OUTPUT);
pinMode (Led_Giallo, OUTPUT);
pinMode (Led_Verde, OUTPUT);
stato_bottoni[0] = 0;
stato_bottoni[1] = 0;
stato_bottoni[2] = 0;
digitalWrite (Led_Rosso, LOW);
digitalWrite (Led_Giallo, LOW);
digitalWrite (Led_Verde, LOW);
}
void aggiornaStato(int bottone, int& statoBottoneVecchio, boolean& statoSwitch)
{
//read pushbutton state
int statoBottoneCorrente = digitalRead (bottone);
//if the state has changed (new state)
//managing the new state
if (statoBottoneCorrente != statoBottoneVecchio)
{
//bouncing
if (statoBottoneCorrente == HIGH)
{
delay(100);
statoSwitch = !statoSwitch;
}
//new state is the current one
statoBottoneVecchio = statoBottoneCorrente;
}
}
void controllaPulsante()
{
aggiornaStato(Rosso_Button, stato_bottoni[0], stato_switch[0]);
aggiornaStato(Giallo_Button, stato_bottoni[1], stato_switch[1]);
aggiornaStato(Verde_Button, stato_bottoni[2], stato_switch[2]);
}
void loop()
{
controllaPulsante();
//**** red led (rosso) is activated by red (rosso) pushbutton
if (stato_switch[0] == 1)
{
digitalWrite(Led_Rosso, HIGH);
}
else
{
digitalWrite(Led_Rosso, LOW);
}
//**** yellow led (giallo) is activated by yellow (giallo) pushbutton
if (stato_switch[1] == 1)
{
digitalWrite(Led_Giallo, HIGH);
}
else
{
digitalWrite(Led_Giallo, LOW);
}
//***** gren led (verde) is activated by green(verde) pushbutton
if (stato_switch[2] == 1)
{
digitalWrite(Led_Verde, HIGH); // turn led on
}
else
{
digitalWrite(Led_Verde, LOW); //turn off led
}
}