Hi all,
i am trying one scenario. in this program i am using while loops to switch on and off the two heaters. so what i need is how many times the heater get on(need to count each time when switch on loop is entered) and after that when i give a digital signal high, total counts need to reset to zero. i have attached the program below:
// constants won't change. They're used here to
// set pin numbers:
const int waterheaterinput = 2; // the number of the pushbutton pin
const int waterheateroutput = 13;
const int milkheaterinput = 3; // the number of the pushbutton pin
const int milkheateroutput = 12;
const int stopatanymoment = 4;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState2 = 0;
int buttonstate3 = 0;
void setup() {
pinMode(waterheateroutput, OUTPUT);
pinMode(milkheateroutput, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(waterheaterinput, INPUT);
pinMode(milkheaterinput, INPUT);
pinMode(stopatanymoment, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(waterheaterinput);
buttonstate3 = digitalRead(stopatanymoment);
while (buttonState == HIGH and buttonstate3 == LOW ) {
digitalWrite(waterheateroutput, HIGH);
break;
}
while (buttonState == LOW or buttonstate3 == HIGH ) {
digitalWrite(waterheateroutput, LOW);
break;
}
buttonState2 = digitalRead(milkheaterinput);
buttonstate3 = digitalRead(stopatanymoment);
while (buttonState2 == HIGH and buttonstate3 == LOW) {
digitalWrite(milkheateroutput, HIGH);
break;
}
while (buttonState2 == LOW or buttonstate3 == HIGH) {
digitalWrite(milkheateroutput, LOW);
break;
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.