I initialized count as 0. However, I know that the loop checking it count == 10 is being entered multiple time because the LCD screen prints pump start time multiple times.
I'm trying to create a timer that starts when a switch is flipped. Any suggestions?
int count=0;
int B_Sw;
void setup() {
Serial.begin(19200);
}
void loop() {
//Handshake
while (count == 0) {
Serial.print(255, BYTE);
Serial.print(1, BYTE);
incoming = Serial.read();
if (int(incoming) == 255) {
connection = Serial.read();
if (int(connection == 1)) {
count = 10;
}
}
}
//Set pump start time
if (Serial.read() == 252) {
B_Sw = Serial.read();
if ((B_Sw == HIGH) && (connection == 1)) {
if (count == 10) {
pumpStartTime = millis();
lcd.setCursor(0,0);
lcd.print("pump start time");
count = 50;
}
}
}
.
.
.
.
This is one of the units in a wireless communication setup. I want them to be connected before continuing, so I need them to run through a loop until they're connected and then never enter it again. That's what I was trying to do with the while() loop. As for the pumpStartTime, I just want that to be set at the time that the B_Sw is set high.
@drhex:
I have the type-casting of incoming as an integer because it's originally a BYTE and I wasn't sure if I could do a comparison between a number and a BYTE. But you're right, the second thing you pointed out is wrong. I was trying to do another type-cast.