I am trying to detect if a switch is ON or OFF from and Arduino, send the data into Python and display the result in a GUI The following Python code will read the serial data into Python as follows; (Not my code i must add)
import serial
ser = serial.Serial('com3',9600)
ser.flushInput()
ser.flushOutput()
while True:
ser.flushInput()
ser.flushOutput()
passcode = ser.read()
if passcode == b'1':
print("Switch is ON")
if passcode == b'0':
print("Switch if OFF")
The results appears as the following on the Python IDE [depending on the result] which is the serial output result
Switch if OFF
Switch if OFF
Switch if OFF
Switch is ON
Switch is ON
Switch is ON
Now my Question ?
Is there any way i can just get "one" reading saying "Switch is On" or "Switch is off" [not the continuous serial result] into Python and Ideally display the result into Tkinter