Last active
November 5, 2015 06:53
-
-
Save waveform80/af91a6f5f198bff3a3c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gpiozero import RyanteckRobot, Button | |
from signal import pause | |
robot = RyanteckRobot() | |
button_actions = { | |
Button(26): robot.forward, | |
Button(16): robot.left, | |
Button(21): robot.right, | |
Button(20): robot.backward, | |
} | |
for btn, action in button_actions.items(): | |
btn.when_pressed = action | |
btn.when_released = robot.stop | |
pause() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from gpiozero import RyanteckRobot as R, Button as B | |
from signal import pause | |
r = R() | |
a = { | |
B(26): r.forward, | |
B(16): r.left, | |
B(21): r.right, | |
B(20): r.backward, | |
} | |
for b, m in button_actions.items(): | |
b.when_pressed = m | |
b.when_released = r.stop | |
pause() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# When the going gets weird, the weird turn pro... | |
from gpiozero import RyanteckRobot as R, Button as B | |
from signal import pause | |
r = R() | |
s = setattr | |
x = lambda b, m: (b, s(b, 'when_pressed', m), s(b, 'when_released', r.stop))[0] | |
l = [x(B(p), m) for p, m in { | |
26: r.forward, | |
16: r.left, | |
21: r.right, | |
20: r.backward, | |
}.items()] | |
pause() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# For the truly bloody minded... | |
from gpiozero import RyanteckRobot as R, Button as B | |
from signal import pause | |
l = [ | |
(lambda b, m: ( | |
b, | |
setattr(b, 'when_pressed', m), | |
setattr(b, 'when_released', r.stop) | |
)[0]) | |
(B(p), m) | |
for r in (R(),) | |
for p, m in ( | |
(26, r.forward), | |
(16, r.left), | |
(21, r.right), | |
(20, r.backward), | |
)] | |
pause() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Help | |
from gpiozero import RyanteckRobot as R, Button as B | |
from signal import pause | |
l = [ | |
(b, s(b, 'when_pressed', m), s(b, 'when_released', r.stop))[0] | |
for r, s in (R(), setattr) | |
for p, m in ( | |
(26, r.forward), | |
(16, r.left), | |
(21, r.right), | |
(20, r.backward), | |
) | |
for b in (B(p),)] | |
pause() |
need to make it smaller ;). a valid option would be to modify the class names and function names to 1 character ones, but that might be a bit extreme
I could also remove all the indentations, but there's some things I just can't bring my self to do, not even for golf! ;-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't seriously claim that 3 or 4 is in any way better, I was more intrigued whether I could come up with a pure functional method of assigning everything and keeping all the references alive at the end. And yes ... it's truly horrid.