I have a piece of code that works, but am wondering if there is way to get it to work without instantiating a BrickPi3 object at the start.
At present my code looks like this:
import brickpi3 import time BP = brickpi3.BrickPi3() speed = 30 stop = 0 inkey = raw_input() if inkey == " ": print ("running forward") BP.set_motor_power(BP.PORT_A, speed) time.sleep(2) print ("stop") BP.set_motor_power(BP.PORT_A, stop) BP.reset_all()
It will run a motor for 2 seconds when the space bar is pressed followed by enter.
I want to make it simpler for students so they don’t need to worry about classes. Any ideas. Also is there a simple way to get the motor to work by pressing the spacebar without having to then press the enter key?
Any ideas most appreciated.