I am using the ultimate 2.0 to make a rumba like bot. the problem Im running into is with the onRead function that is called by the ultrasonicRead function. the function will not allow return variables or global variables to use the distance in the rest of the code.
here is a simple test code to use global variables :
from megapi import *
x = 0
dist = 0
dist = v
x = 3
if name== “main”:
sqr = square(3) print(sqr) print(x) bot.ultrasonicSensorRead(7,onRead) print(dist)
and here is the result :
Version:3.7.3 (default, Dec 20 2019, 18:57:59)
<megapi_python3.mSerial object at 0xb5ec7e30>
as you can see my test function works but not the ultrasonic one. Anyone know the reason for this or a way to work around it?