Just a quick question on a small script taht is for some reason not working
I ran this script:
import serial
import time
import turtle
def serialreading():
serialPort = serial.Serial(
port="COM5", baudrate=9600, bytesize=8, timeout=2, stopbits=serial.STOPBITS_ONE
)
# Read data out of the buffer until a carraige return / new line is found
serialString = serialPort.readline()
turtlenumber = serialString.decode("Ascii")
# Print the contents of the serial data to ASCII
try:
print(turtlenumber)
except:
pass
def roomview():
t = turtle.Turtle()
t.speed(0) # 1:slowest, 3:slow, 5:normal, 10:fast, 0:fastest
t.forward(turtlenumber)
time.sleep(1)
turtle.reset()
while 1 > 0:
serialreading()
roomview()
with the goal for turtle to simply draw a line as long as the number coming into the serial communication (its variable being turtlenumber). for this example, the number should have been 1192, but i never got to see it in action since the shell is telling me “NameError: name ‘turtlenumber’ is not defined“
Pls help me out
New contributor
Aayan Rehman is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.