How to update Serial.print statement in realtime using Arduino

北城以北 提交于 2019-12-25 16:55:32

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!