from cgitb import text
from distutils.cmd import Command
import tkinter as tk
from socket import timeout
import time
import pyfirmata
import time
from time import sleep, strftime
from tkinter import Tk, Label
from tkinter import Tk, Label
import random
import os 
import tkinter.font as tkFont
ports="COM4"
board = pyfirmata.Arduino('COM4')  
analog_pin0 = board.get_pin('a:1:i') 
x=0
it = pyfirmata.util.Iterator(board)  
it.start()
pin=4
analog_pin0.enable_reporting() 
board.digital[7].write(0)
voltage0 = "" 
def main():
   print("this is maoin")
def on():
      global voltage0
      root = tk.Tk()
      root.geometry("600x500")
 
      w = tk.Label(root, text="Hello, world!")
      w.pack(pady=20)  
      # B = tk.Button(root, text ="Hello", command = main) 
      # B.pack()
      w.config(text=voltage0)
      w['text'] = "intial voltage"
      B = tk.Button(root, text ="Hello", command = main)
      B.pack() 
      root.mainloop()  
      def main ():
         while True:
     
            global voltage0
            reading0 = analog_pin0.read()
            if reading0 != None:
               voltage0 = reading0 * 22.3
               voltage0 = round(voltage0,2)
               time.sleep(0.1)
               print(voltage0)
               w.config(text=voltage0)
               w['text'] = voltage0
               
               
            else:
               voltage0 = float('nan')
            
            
            
            
            string = strftime('%H:%M:%S %p')
                  
            
            
            if (voltage0>7.3):
               time.sleep(0.1)  
               board.digital[pin].write(1)
               board.digital[6].write(0) 
               
            if(voltage0<6.5):
                  time.sleep(0.1)  
                  board.digital[pin].write(0)
                  board.digital[6].write(1) 
            
            if (voltage0==7.3):
               
               
               print()
               print(voltage0)
               print(string)
               w.config(text=voltage0)
               w['text'] = voltage0
            if (voltage0==6.5):
               
               print()
               print(voltage0)
               print(string)  
               w.config(text=voltage0)
               w['text'] = voltage0
      
      main()
     
on()
serial output not display in tkinter label
54 Views Asked by City of krunkers At
        	0