self.afterId = None root.bind('<KeyPress>', self.key_press) root.bind('<KeyRelease>', self.key_release) def key_press(self, event): if self.afterId != None: self.after_cancel( self.afterId ) self.afterId = None else: 'key pressed %s' % event.char if event.char == "w": text.insert('end', ' FORWARD ') ServoCounterClockwise(servoLeft) ServoClockwise(servoRight) elif event.char == "s": text.insert('end', ' RIGHT_TURN ') ServoCounterClockwise(servoLeft) ServoCounterClockwise(servoRight) elif event.char == "K": text.insert('end', ' Quit ') pwm.setPWM(0, 0, servoZero) root.destroy() elif event.char == "z": text.insert('end', ' BACKWARD ') ServoClockwise(servoLeft) ServoCounterClockwise(servoRight) elif event.char == "a": text.insert('end', ' LEFT_TURN ') ServoClockwise(servoLeft) ServoClockwise(servoRight) elif event.char == "u": text.insert('end', ' UP ') ServoClockwise(servoLift) elif event.char == "d": text.insert('end', ' DOWN ') ServoCounterClockwise(servoLift) elif == "c": text.insert('end', ' CLOSE_GRIP ') ServoClockwise(servoGrip)
self.afterId = None root.bind('<KeyPress>', self.key_press) root.bind('<KeyRelease>', self.key_release) def key_press(self, event): if self.afterId != None: self.after_cancel( self.afterId ) self.afterId = None else: 'key pressed %s' % event.char if event.char == "w": text.insert('end', ' FORWARD ') ServoCounterClockwise(servoLeft) ServoClockwise(servoRight) elif event.char == "s": text.insert('end', ' RIGHT_TURN ') ServoCounterClockwise(servoLeft) ServoCounterClockwise(servoRight) elif event.char == "K": text.insert('end', ' Quit ') pwm.setPWM(0, 0, servoZero) root.destroy() elif event.char == "z": text.insert('end', ' BACKWARD ') ServoClockwise(servoLeft) ServoCounterClockwise(servoRight) elif event.char == "a": text.insert('end', ' LEFT_TURN ') ServoClockwise(servoLeft) ServoClockwise(servoRight) elif event.char == "u": text.insert('end', ' UP ') ServoClockwise(servoLift) elif event.char == "d": text.insert('end', ' DOWN ') ServoCounterClockwise(servoLift) elif == "c": text.insert('end', ' CLOSE_GRIP ') ServoClockwise(servoGrip)
robotics_code_handout.docx