def reverse(revs, speed): robohat.reverse(speed) clicks = int(revs*CLICKS_PER_REV) # doesn't matter which side's sensor we use s = sensors[SENS_L] s.start(clicks).wait(5) robohat.stop() time.sleep(1) print("final clicks: ", s._sensorClicks)
#====================================================================== speed = 60 robohat.init() # main loop try: while True: keyp = readkey() if keyp == 'w' or ord(keyp) == 16: robohat.forward(speed) print ('Forward', speed) elif keyp == 'z' or ord(keyp) == 17: robohat.reverse(speed) print ('Reverse', speed) elif keyp == 's' or ord(keyp) == 18: robohat.spinRight(speed) print ('Spin Right', speed) elif keyp == 'a' or ord(keyp) == 19: robohat.spinLeft(speed) print ('Spin Left', speed) elif keyp == '.' or keyp == '>': speed = min(100, speed+10) print ('Speed+', speed) elif keyp == ',' or keyp == '<': speed = max (0, speed-10) print ('Speed-', speed) elif keyp == ' ': robohat.stop()
print "Use . or > to speed up" print "Speed changes take effect when the next arrow key is pressed" print "Press Ctrl-C to end" print robohat.init() # main loop try: while True: keyp = readkey() if keyp == 'w' or ord(keyp) == 16: robohat.forward(speed) print 'Forward', speed elif keyp == 'z' or ord(keyp) == 17: robohat.reverse(speed) print 'Reverse', speed elif keyp == 's' or ord(keyp) == 18: robohat.spinRight(speed) print 'Spin Right', speed elif keyp == 'a' or ord(keyp) == 19: robohat.spinLeft(speed) print 'Spin Left', speed elif keyp == '.' or keyp == '>': speed = min(100, speed+10) print 'Speed+', speed elif keyp == ',' or keyp == '<': speed = max (0, speed-10) print 'Speed-', speed elif keyp == ' ': robohat.stop()