https://github.com/codeadamca/spike-buttons
A basic example of using MicroPython and the buttons on the LEGO Spike hub.
https://github.com/codeadamca/spike-buttons
lego mindstorms python spike
Last synced: 6 months ago
JSON representation
A basic example of using MicroPython and the buttons on the LEGO Spike hub.
- Host: GitHub
- URL: https://github.com/codeadamca/spike-buttons
- Owner: codeadamca
- Created: 2022-07-09T01:14:49.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-01-26T22:26:03.000Z (8 months ago)
- Last Synced: 2025-01-26T23:21:25.705Z (8 months ago)
- Topics: lego, mindstorms, python, spike
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# LEGO® Mindstorms® Spike Hub and the Hub Buttons
A Python snippet utilizing the LEGO Spike buttons, [MicroPython](https://lego.github.io/MINDSTORMS-Robot-Inventor-hub-API/), and the `is_pressed()` and `is_released()` commands.
## Sample Code
```py
from mindstorms import MSHub
from mindstorms.control import wait_for_secondshub = MSHub()
while True:
if hub.left_button.is_pressed() and hub.right_button.is_pressed():
break
elif hub.left_button.is_pressed():
hub.speaker.start_beep(50)
hub.status_light.on('violet')
hub.light_matrix.show_image('ARROW_W')hub.left_button.wait_until_released()
elif hub.right_button.is_pressed():
hub.speaker.start_beep(70)
hub.status_light.on('green')
hub.light_matrix.show_image('ARROW_E')hub.right_button.wait_until_released()
hub.speaker.stop()
hub.status_light.off()
hub.light_matrix.off()wait_for_seconds(1)
hub.speaker.beep(90)
hub.speaker.beep()
```***
## Repo Resources
* [Visual Studio Code](https://code.visualstudio.com/)
* [MicroPython for LEGO Robot Inventor](https://www.lego.com/en-ca/themes/mindstorms/downloads)
* [LEGO Mindstorms](https://www.lego.com/en-ca/themes/mindstorms)
* [LEGO Mindstorms App for Mac](https://apps.apple.com/us/app/lego-mindstorms-inventor/id1515448947)
* [LEGO Mindstorms App for Android](https://play.google.com/store/apps/details?id=com.lego.retail.mindstorms)
* [LEGO Mindstorms App for Windows](https://www.microsoft.com/store/apps/9N7GN3KC2GK6)