I built a Python program that records input from an Arduino Potentiometer and displays it into the Python console. I now am building a nicer output location as a local HTML file and am looking for advice on how I would do such a thing onto an already built HTML page, and have it update the page in real time as the Arduino receives input. Below is an example of my main Python code that I would like to display on the page:
from Arduino import Arduino
import time
board = Arduino("9600")
board.pinMode(2, "INPUT")
board.digitalWrite(2, "HIGH")
while True:
button_click = board.digitalRead(2)
if button_click == 1:
is_button_click = False
else:
is_button_click = True
x_value = board.analogRead(0)
y_value = board.analogRead(1)
print("X-Value: " + str(x_value))
print("Y-Value: " + str(y_value))
print("Clicked?: " + str(button_click))
time.sleep(0.25)
The HTML page is already built but the "code" of it is quite long and I figure that it doesn't matter much since most HTML pages follow the same basic structure. Ignore my useless if/else statement. I am going to use that later for something.
How would you recommend printing the variables x_value, y_value, and button_click on my HTML page in real time? I would prefer that it replaces the previous output too rather than generating an infinite stream of outputs, and clears the output when the program is done running. Some ideas I had were maybe creating a canvas or using some sort of JS code but I haven't used JavaScript in years. My entire project is local and will remain local to my computer if that helps. Thank you in advance!