I am programming an Arduino and I would like to have my if statement only respond when the voltage increases, not when it decreases.
This is what I have now:
void setup() {
Serial.begin(9800);
pinMode(13, OUTPUT);
}
void loop() {
int sensorValue5 = analogRead(A5);
float voltage5 = sensorValue5 * (5.0 / 1023.0);
Serial.println(voltage5);
if (voltage5 > 0.56 && voltage5 < 0.66) {
digitalWrite(13, HIGH);
Serial.println("TURNING BULB ON!");
delay(200);
digitalWrite(13, LOW);
Serial.println("TURNING BULB OFF!");
}
}
The problem with this code is that the if statement executes when the voltage increases from below 0.56 volts, but it also executes when the voltage decreases from higher than 0.66 volts. I would like the if statement to execute only when the voltage is going up, not coming back down.
Please help me this is very important. Thank you.
Aucun commentaire:
Enregistrer un commentaire