Advertisement
Guest User

Untitled

a guest
Apr 5th, 2017
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. from BrickPi import *
  2. import curses, time
  3. BrickPiSetup()
  4. BrickPi.SensorType[PORT_4] = TYPE_SENSOR_EV3_TOUCH_0
  5. BrickPiSetupSensors()
  6. BrickPi.MotorEnable[PORT_D] = 1
  7. stdscr = curses.initscr() #initialize the curses object
  8. curses.cbreak() #to get special key characters
  9. stdscr.keypad(1) #for getting values such as KEY_UP
  10. key = ''
  11. while key!= ord('q'):
  12. key = stdscr.getch() #get a character from terminal
  13. BrickPi.MotorSpeed[PORT_D] = 0 #first setting all speeds to zero
  14. stdscr.refresh()
  15. result = BrickPiUpdateValues()
  16. if not result:
  17. if key == curses.KEY_LEFT :
  18. BrickPiUpdateValues()
  19. button_value1 = BrickPi.Sensor[PORT_4]
  20. if button_value1 < 1020:
  21. BrickPi.MotorSpeed[PORT_D] = 255
  22. if button_value1 > 1020:
  23. BrickPi.MotorSpeed[PORT_D] = 0
  24. elif key == curses.KEY_RIGHT :
  25. BrickPi.MotorSpeed[PORT_D] = -255
  26. ot = time.time()
  27. while(time.time() - ot < (1.00)):
  28. BrickPiUpdateValues() # Ask BrickPi to update values for sensors/motors
  29. time.sleep(.1)
  30. time.sleep(.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement