Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from BrickPi import *
- import curses, time
- BrickPiSetup()
- BrickPi.SensorType[PORT_4] = TYPE_SENSOR_EV3_TOUCH_0
- BrickPiSetupSensors()
- BrickPi.MotorEnable[PORT_D] = 1
- stdscr = curses.initscr() #initialize the curses object
- curses.cbreak() #to get special key characters
- stdscr.keypad(1) #for getting values such as KEY_UP
- key = ''
- while key!= ord('q'):
- key = stdscr.getch() #get a character from terminal
- BrickPi.MotorSpeed[PORT_D] = 0 #first setting all speeds to zero
- stdscr.refresh()
- result = BrickPiUpdateValues()
- if not result:
- if key == curses.KEY_LEFT :
- BrickPiUpdateValues()
- button_value1 = BrickPi.Sensor[PORT_4]
- if button_value1 < 1020:
- BrickPi.MotorSpeed[PORT_D] = 255
- if button_value1 > 1020:
- BrickPi.MotorSpeed[PORT_D] = 0
- elif key == curses.KEY_RIGHT :
- BrickPi.MotorSpeed[PORT_D] = -255
- ot = time.time()
- while(time.time() - ot < (1.00)):
- BrickPiUpdateValues() # Ask BrickPi to update values for sensors/motors
- time.sleep(.1)
- time.sleep(.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement