Skip to content

Instantly share code, notes, and snippets.

@ntoll
Created August 8, 2017 14:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ntoll/0ef2aa819117a696f0341508b64ecd2b to your computer and use it in GitHub Desktop.
Save ntoll/0ef2aa819117a696f0341508b64ecd2b to your computer and use it in GitHub Desktop.
A really crap Tamagotchi for micro:bit
# 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