All:
Appreciate some help, I am sure the solution is simple. Basically in the Loop() I want the code that toggles outputs on and off to run without interruption UNTIL it receives data from the serial port. This doesn't work because the while() is in a endless loop until some data is received, so the port toggling never occurs.
void loop() {
unsigned long currentMillis = micros(); //for timing
char inchar;
while (!Serial.available()); //stay here as long as COM port is empty
inchar = Serial.read(); // read next available byte
if( inchar == 'd' || inchar == 'D') {
USARTDisplay();
}
else if( inchar == 's'|| inchar == 'S') {
USARTMenu();
}
if((outpin_state == HIGH) && (currentMillis - previousMillis >= co2_ontime)) {
outpin_state = LOW;
previousMillis = currentMillis;
digitalWrite(CO2_OUTPIN, LOW);
}
else if ((outpin_state == LOW) && (currentMillis - previousMillis >= co2_offtime))
{
outpin_state = HIGH;
previousMillis = currentMillis;
digitalWrite(CO2_OUTPIN, HIGH);
}
}