I want to have a condition verify to be TRUE, but right after it will turn FALSE , but I still want the code to run. Much like having a momentary switch that tripped the system to start.
What I'm trying to achieve having firstPin read HIGH with water present, then have it dispense all the way until secondPin is FALSE (no water touching it anymore). So, after firstPin reads HIGH (ok you can dispense now) it will eventually go FALSE as the water dips below the first pin. I only want it to stop when the secondPin reads LOW/FALSE.
Where do I start? Here is some code but it might not help much. If you could help just by explaining and not using the code, that would be great to!
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int secondRead = 4;
const int ledPin = 13; // the number of the LED pin
unsigned long time;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonStatetwo = 0;
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
pinMode(secondRead, INPUT);
Serial.begin(9600);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
buttonStatetwo = digitalRead(secondRead);
//check if buttonPin2 is HIGH and you have enough water to start
if (buttonState == HIGH) {while (buttonState == HIGH || buttonState == LOW) && (buttonStatetwo == HIGH){
digitalWrite(ledPin, HIGH);
Serial.print("Time: ");
time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1150);
}
}
// turn LED off:
digitalWrite(ledPin, LOW);
}