Created
August 8, 2017 14:38
-
-
Save ntoll/0ef2aa819117a696f0341508b64ecd2b to your computer and use it in GitHub Desktop.
A really crap Tamagotchi for micro:bit
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
# Make the display sparkle. Click button A to show an image for | |
# a moment before the sparkles start again. Click button B to | |
# scroll a friendly message before the sparkles return. | |
# By Nicholas H.Tollervey and released to the Public Domain. | |
# How would you improve this code? | |
from microbit import * | |
import random | |
# A full list of images can be found here: http://bit.ly/1WY221q | |
images = [Image.HAPPY, Image.SAD, Image.GHOST, Image.SKULL, | |
Image.DUCK, Image.UMBRELLA, Image.GIRAFFE, Image.RABBIT, | |
Image.HEART, Image.ANGRY, Image.STICKFIGURE] | |
while True: | |
sleep(20) | |
x = random.randint(0, 4) | |
y = random.randint(0, 4) | |
brightness = random.randint(0, 9) | |
display.set_pixel(x, y, brightness) | |
if button_a.was_pressed(): | |
display.show(random.choice(images)) | |
sleep(500) | |
if button_b.was_pressed(): | |
display.scroll("Hello, World!", delay=100) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment