mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2025-10-29 17:50:37 +00:00
27 lines
537 B
Python
27 lines
537 B
Python
from gpiozero import Robot
|
|
from bluedot import BlueDot
|
|
from signal import pause
|
|
|
|
def pos_to_values(x, y):
|
|
left = y if x > 0 else y + x
|
|
right = y if x < 0 else y - x
|
|
return (clamped(left), clamped(right))
|
|
|
|
def clamped(v):
|
|
return max(-1, min(1, v))
|
|
|
|
def drive():
|
|
while True:
|
|
if bd.is_pressed:
|
|
x, y = bd.position.x, bd.position.y
|
|
yield pos_to_values(x, y)
|
|
else:
|
|
yield (0, 0)
|
|
|
|
robot = Robot(left=(4, 14), right=(17, 18))
|
|
bd = BlueDot()
|
|
|
|
robot.source = drive()
|
|
|
|
pause()
|