system
July 14, 2014, 10:09am
1
Hi guys,
I'd like to have your help because I have a program that should control 5 leds (pompa1, pompa2, pompa3, pompa4, valvola) using 3 bottons (interruttore,cronotermostato,orologio). I'll attach the program that I've done because there may be some errors that I can't see. I hope you can be helpful for me.
Thank you for your attention.
sketch_jul11a.ino (1.83 KB)
Instead of,
buttonState = digitalRead(interruttore);//Legge lo stato del bottone
if (interruttore == HIGH)
put if (buttonState == HIGH)
system
July 14, 2014, 10:23am
3
I tryed to do that, but it seems like the program doesn't care the "if" instruction and only do the "else".
Infact no matter what I do, arduino only do that.
why?
Thank you very much
AnalogReadSerial.ino (181 Bytes)
you need to modify else condition also.
since you had put a ';' at the end of else.. so that else condition terminated there.
use
else
{
digitalWrite (pompa2,HIGH);
digitalWrite (pompa4,HIGH);
digitalWrite (pompa3,HIGH);
digitalWrite (pompa1,LOW);
digitalWrite (valvola,LOW);
}
it may solve your issue. your code has many bugs.. use below code as a reference..
const int interruttore = 9;
int pompa1 = 2;
int pompa2 = 3;
int pompa3 = 4;
int pompa4 = 5;
const int cronotermostato = 12;
const int orologio = 11;
int valvola = 8;
byte buttonState1 = LOW;
byte buttonState2 = LOW;
byte buttonState3 = LOW;
void setup ()
{
pinMode(interruttore,INPUT);
pinMode(pompa1,OUTPUT);
pinMode(pompa2,OUTPUT);
pinMode(pompa3,OUTPUT);
pinMode(pompa4,OUTPUT);
pinMode(cronotermostato,INPUT);
pinMode(orologio,INPUT);
pinMode(valvola,OUTPUT);
}
void loop ()
{
buttonState1 = digitalRead(interruttore);//Legge lo stato del bottone
if (buttonState1 == HIGH)
{
buttonState1 == LOW;
buttonState2 = digitalRead(cronotermostato);
if (buttonState2 == HIGH)
{
digitalWrite ( pompa2, HIGH );
digitalWrite ( pompa4, HIGH );
}
else
{
digitalWrite ( pompa2, LOW );
digitalWrite ( pompa4, LOW );
}
buttonState3 = digitalRead(orologio);//Legge lo stato del bottone
if (buttonState3 == HIGH)
{
digitalWrite ( pompa3, HIGH );
}
else
{
digitalWrite ( pompa3, LOW );
}
if ( pompa2==HIGH || pompa4==HIGH)
{
digitalWrite (pompa1,HIGH);
digitalWrite (valvola,HIGH);
}
else
{
digitalWrite (pompa1,LOW);
digitalWrite (valvola,LOW);
}
buttonState1 = digitalRead(interruttore);//Legge lo stato del bottone
}
else
{
digitalWrite (pompa2,HIGH);
digitalWrite (pompa4,HIGH);
digitalWrite (pompa3,HIGH);
digitalWrite (pompa1,LOW);
digitalWrite (valvola,LOW);
}
}
system
July 14, 2014, 1:52pm
5
Thank You so much for your help!!!!!! I've just finished the program