So, my main goal is to make a stopwatch with Tkinter, in which time is stoppped with an external pushbutton
My void loop function in Arduino Uno is
void loop() {
if(digitalRead(BUTTON) == HIGH){
Serial.print("E\n");
digitalWrite(LED, HIGH);
while(1){
if(digitalRead(BUTTON) == HIGH){
continue;
}
if(digitalRead(BUTTON) == LOW){
break;}
}
}
}
Basically, whenever the pushbutton is pressed I send via serial the message "E\n" and the arduino enters in an infinte loop that only breaks when the pushbutton stops being pressed (to avoid sending more than one message).
Then I have my Python code that reads the serial through the serial.readline() function.
Part of my Python code is (remember that i'm making a stopwatch and time is appearing in the screen - variable timer[i] is what saves the second and the ms):
def update_timeText():
if (state):
global timer
# Every time this function is called,
# it increments 1/100 of a second
timer[1] += 1
# Every 100 centisecond is equal to 1 second
if (timer[1] >= 100):
timer[1] = 0
timer[0] += 1
if arduino.readline() == 'E\n':
print("FLAG\n")
# TIME STRING
timeString = pattern.format(timer[0], timer[1])
# UPTADE THE LABEL WITH TIME STRING
timeText.configure(text=timeString)
# Call the update_timeText() function after 1 centisecond
root.after(10, update_timeText)
The variable state goes True whenever I start the stopwatch (via a Tkinter button, but that's irrelevant for this case).
My problem, is that the program stops in the line
if arduino.readline() == 'E\n':
i.e., it only continues if I press the pushbutton. What I think that is happening, is that the .readline() continues waiting and waiting until it receives the message 'E\n'... I've tried with the .readline.strip() and also only .read() but none of them worked.
It is though very strange, because if the condition in front of If is not verified, it should just continue...
Any suggestion?
arduino
object?) I'll try to help.