Created
February 17, 2022 11:29
-
-
Save Philippe-Locquet/8cee4dc788a7528dc698d28592f6d744 to your computer and use it in GitHub Desktop.
Battery Level Fun program for Mindstorms Robot Inventor 51515
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
Battery Level Fun program for Mindstorms Robot Inventor 51515 | |
This is my take on a fun battery level program for the Mindstorms 51515 Robot Inventor | |
At the lowest level (under 10%) it displays the image of a plug. The remaining battery states are displayed via bars (similar to cell network on phones). Each battery state has a specific sound and Main button led color associated. | |
This program shows how I circumvented issues, I'm sure there is a way to rewrite this in more concise fashion, so feel free to contribute! | |
AKN: Was useful to the creation of this program material posted online by: Anton's Mindstorms hacks Artpoz (on GitHub) lego.github.io And the help guides in the Mindstorms App |
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 mindstorms import MSHub, Motor, MotorPair, ColorSensor, DistanceSensor, App | |
from mindstorms.control import wait_for_seconds, wait_until, Timer | |
from mindstorms.operator import greater_than, greater_than_or_equal_to, less_than, less_than_or_equal_to, equal_to, not_equal_to | |
import math | |
import hub | |
# Create your objects here. | |
# Write your program here. | |
battery = hub.battery.capacity_left() | |
print(battery) | |
#Displays image plug | |
if (battery <= 10): | |
hub.led(3) | |
hub.display.pixel(0,3,9) | |
hub.display.pixel(0,2,9) | |
hub.display.pixel(1,4,9) | |
hub.display.pixel(1,3,9) | |
hub.display.pixel(1,2,9) | |
hub.display.pixel(1,1,9) | |
hub.display.pixel(1,0,9) | |
hub.display.pixel(2,4,9) | |
hub.display.pixel(2,3,9) | |
hub.display.pixel(2,2,9) | |
hub.display.pixel(3,4,9) | |
hub.display.pixel(3,3,9) | |
hub.display.pixel(3,2,9) | |
hub.display.pixel(3,1,9) | |
hub.display.pixel(3,0,9) | |
hub.display.pixel(4,3,9) | |
hub.display.pixel(4,2,9) | |
hub = MSHub() | |
hub.speaker.play_sound('Horn') | |
hub.speaker.play_sound('Horn') | |
hub.speaker.play_sound('Horn') | |
#displays 1 bar (single pixel) | |
elif (battery <= 20): | |
hub.led(8) | |
hub.display.pixel(0,4,9) | |
hub = MSHub() | |
hub.speaker.play_sound('Sad') | |
#displays 2 small bars | |
elif (battery <= 40): | |
hub.led(7) | |
hub.display.pixel(0,4,9) | |
hub.display.pixel(1,4,9) | |
hub.display.pixel(1,3,9) | |
hub = MSHub() | |
hub.speaker.play_sound('Scanning') | |
#Displays 3 bars | |
elif (battery <= 60): | |
hub.led(4) | |
hub.display.pixel(0,4,9) | |
hub.display.pixel(1,4,9) | |
hub.display.pixel(1,3,9) | |
hub.display.pixel(2,4,9) | |
hub.display.pixel(2,3,9) | |
hub.display.pixel(2,2,9) | |
hub = MSHub() | |
hub.speaker.play_sound('Ping') | |
#Displays 4 bars | |
elif (battery <= 80): | |
hub.led(5) | |
hub.display.pixel(0,4,9) | |
hub.display.pixel(1,4,9) | |
hub.display.pixel(1,3,9) | |
hub.display.pixel(2,4,9) | |
hub.display.pixel(2,3,9) | |
hub.display.pixel(2,2,9) | |
hub.display.pixel(3,4,9) | |
hub.display.pixel(3,3,9) | |
hub.display.pixel(3,2,9) | |
hub.display.pixel(3,1,9) | |
hub = MSHub() | |
hub.speaker.play_sound('Play') | |
#Displays 5 bars | |
elif (battery <= 100): | |
hub.led(6) | |
hub.display.pixel(0,4,9) | |
hub.display.pixel(1,4,9) | |
hub.display.pixel(1,3,9) | |
hub.display.pixel(2,4,9) | |
hub.display.pixel(2,3,9) | |
hub.display.pixel(2,2,9) | |
hub.display.pixel(3,4,9) | |
hub.display.pixel(3,3,9) | |
hub.display.pixel(3,2,9) | |
hub.display.pixel(3,1,9) | |
hub.display.pixel(4,4,9) | |
hub.display.pixel(4,3,9) | |
hub.display.pixel(4,2,9) | |
hub.display.pixel(4,1,9) | |
hub.display.pixel(4,0,9) | |
hub = MSHub() | |
hub.speaker.play_sound('Celebrate') | |
wait_for_seconds(5) | |
hub.display.clear() | |
raise SystemExit | |
0 comments on commit 019c38f |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment