Skip to content

Instantly share code, notes, and snippets.

@darrell24015
Forked from ntoll/crapamagotchi.py
Created December 2, 2019 15:24
Show Gist options
  • Save darrell24015/497780d9a034b3ced91adb2a8a0e0fbb to your computer and use it in GitHub Desktop.
Save darrell24015/497780d9a034b3ced91adb2a8a0e0fbb 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)
@darrell24015
Copy link
Author

Foundation for a microPET game, perhaps?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment