mirror of
https://github.com/KevinMidboe/python-gpiozero.git
synced 2026-02-01 22:26:14 +00:00
Add more advanced and remote recipes
This commit is contained in:
26
docs/examples/bluedot_robot_2.py
Normal file
26
docs/examples/bluedot_robot_2.py
Normal file
@@ -0,0 +1,26 @@
|
||||
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()
|
||||
Reference in New Issue
Block a user