Python Megapi Raspberry pi Programm Problem


#1

Hello
I have written a Python subroutine with which I control over the Raspberry pi the Megapi. Something like this works.
If I want to quit the program I do not come back from the terminal and the motors sum easily.

What am I doing wrong?

from megapi import *
bot = MegaPi()
bot.start()
sleep(1);
def setMotorLeft(power):
bot.encoderMotorRun(2,power);

def setMotorRight(power):
bot.encoderMotorRun(2,power);

def exit():
bot.encoderMotorRun(1,0);
bot.encoderMotorRun(2,0);
bot.close()
bot.exit()


#2

I might rearrange the code thusly:

from megapi import *

def exit():
    bot.encoderMotorRun(1,0)
    bot.encoderMotorRun(2,0)
    bot.close()

def setMotorLeft(power):
    bot.encoderMotorRun(2,power)

def setMotorRight(power):
    bot.encoderMotorRun(2,power)

def myFunc():
    bot = MegaPi()
    bot.start()
    sleep(1)
    bot.exit()

If you want to use myFunc as your main, then change myFunc to main and add the following couple of lines:

if __name__ == "__main__":
    main()

Also, if I recall correctly, Python does not require semicolons to indicate end of line.

Just a quick thought.


#3