Hello,
Has anybody found a good solution to get sensor values to the main function (or any other function).
I call
bot.ultrasonicSensorRead(Slot,onRead)
And from
def onRead(sensorData):
…
I would like to return sensorData to use it where bot.ultrasonicSensorRead was called and I haven‘t found any solution.
Can anyone help?
Thanks
MegaPi Python Callbacks Problem
Kuttel
#1
dr-roboto
#2
I have been using the PI to talk to my orion, Here is my test code for the ultrasonic:
tst program to talk to makeblock
from megapi import *
distance = 123
def onRead(v):
global distance
print(“distance:”+str(v)+" cm")
distance = v
bot = MegaPi()
bot.start()
my code
bot.motorRun(M1,0)
sleep(2)
print (“start test”)
while 1:
sleep(2)
bot.ultrasonicSensorRead(3,onRead)
print (distance)
idist = int(distance)
if idist < 12:
print("time to turn")
system
#3
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.