Search code examples
pythonarduinointegerarduino-uno

I want to print a number i got from a def value. but i want to convert the def into an integer. Is there a way


import serial
import subprocess

ser = serial.Serial('COM3', baudrate = 9600, timeout = 1)
file = open('C://Users//adith//Documents//Code//Local-Sys-Files//Python//Sensor stuff uwu//comfirm.txt','r')
file1 = open('C://Users//adith//Documents//Code//Local-Sys-Files//Python//Sensor stuff uwu//comfirm.txt','r')
f=file.readline()
def getValues():
    ser.write(b'g')
    arduinoData = ser.readline().decode('ascii')
    return arduinoData

    
while (getValues<=40):
    file.write("False")
while (getValues==40):
    file.write("False")
while (getValues>=40):
    file.write("True")


while (f=="True"): (
subprocess.call("C://Users//Toasted//AppData//Roaming//Spotify//Spotify.exe")
) 

I want to comare getValues with "40" but i can't do it since its not an integer so how could I change getValues into an integer. getValues is basically reading of a serial monitor on Arduino


Solution

  • Convert the ardunioData to int and then use return and while calling the function make sure to use paranthesis'()'.

    # In function
    ar=int(ardunioData)
    return ar
    
    # when using while:
    while getValues()>=40:
        file.write('False')