问题
I have the following sketch, https://github.com/ipatch/KegCop/blob/master/KegCop-Bluno-sketch.c that I'm running on Arduino UNO compatible microcontroller. However I am trying to print statements while the flowmeter is in use with the following function,
// flowmeter stuff
bool getFlow4() {
// call the countdown function for pouring beer
// Serial.println(flowmeterPin);
flowmeterPinState = digitalRead(flowmeterPin);
// Serial.println(flowmeterPinStatePinState);
volatile unsigned long currentMillis = millis();
// if the predefined interval has passed
if (millis() - lastmillis >= 250) { // Update every 1/4 second
// disconnect flow meter from interrupt
detachInterrupt(0); // Disable interrupt when calculating
// Serial.print("Ticks:");
Serial.print(numTicks);
// numTicks = 0; // Restart the counter.
lastmillis = millis(); // Update lastmillis
attachInterrupt(0, count, FALLING); // enable interrupt
}
if(numTicks >= 475 || valveClosed == 1) {
close_valve();
numTicks = 0; // Restart the counter.
valveClosed = 0;
return 0;
}
}
However, the print
statements only get updated once the flowmeter has stopped operating. Any help would greatly be appreciated. As I would like the print
statements to be updated while the flowmeter is in use.
来源:https://stackoverflow.com/questions/33817972/how-to-update-serial-print-statement-in-realtime-using-arduino