Hello I wanted two functions parallel with threading run however functioned the night since already in Megapi a threading runs.
How can I run multiple functions in parallel?
Megapi import
from megapi import *
import time, os, random
from threading import Thread
global stopp_turn
global time_stopp
def onRead(v):
global Ultraschall;
Ultraschall = v;
#print "distance:"+str(Ultraschall)+" cm";
# So lange stopp = 0 arbeitet dieser Thread in der
# Endlosschleife.
def control():
global stopp_control
global time_stopp
stopp_control = 0
turn_degree = 0
bot = MegaPi()
bot.start()
sleep(1);
while stopp_control == 0:
sleep(1);
bot.encoderMotorRun(1,100);
bot.encoderMotorRun(2,100);
sleep(1);
bot.encoderMotorRun(1,0);
bot.encoderMotorRun(2,0);
if time_stopp < time.time():
stopp_control = 1
print "Programm Ende";
def sensoren():
global stopp_control
global time_stopp
stopp_control = 0
bot = MegaPi()
bot.start()
sleep(1);
while stopp_control == 0:
bot.ultrasonicSensorRead(7,onRead);
print "Thread Sensor Run";
sleep(1);
laufzeit=input("Bitte die Zeit in Minuten eingeben die das Roboter-Auto fahren soll: ")
time_stopp = laufzeit*60 + time.time()
t_control = Thread(target=control)
t_sensoren = Thread(target=sensoren)
t_control.start()
t_sensoren.start()