micro:bit Projects
micro:bit Projects
from microbit import *
while True:
display.scroll("Sam") # Replace with your name
sleep(1000) # Pauses before displaying the name
Description:
The micro:bit shows a beating heart (appearing and disappearing).
from microbit import *
while True:
display.show(Image.HEART)
sleep(500)
display.show(Image.HEART_SMALL)
sleep(500)
Description:
The micro:bit shows an emotion based on the button pressed.
from microbit import *
while True:
if button_a.is_pressed():
display.show(Image.HAPPY)
if button_b.is_pressed():
display.show(Image.SAD)
Description:
The micro:bit counts up and down depending on the button pressed.
from microbit import *
count = 0
while True:
if button_a.is_pressed():
if count > 0:
count = count - 1
display.show(count)
if button_b.is_pressed():
count = count + 1
display.show(count)
from microbit import *
import random
while True:
if accelerometer.was_gesture('shake'):
display.show(random.randint(1, 6))
Description:
The micro:bit displays the current temperature of the area when button A is pressed.
from microbit import *
while True:
if button_a.was_pressed():
display.scroll(temperature())
Description:
The micro:bit detects the light levels and displays an image of a sun when a certain light level is reached.
from microbit import *
while True:
if display.read_light_level() > 100:
display.show(Image(
"90909:"
"09990:"
"99999:"
"09990:"
"90909:"))
else:
display.clear()
from microbit import *
compass.calibrate()
while True:
bearing = compass.heading()
if bearing < 10 or bearing > 340:
display.show('N')
else:
display.show(' ')
Challenge:
Can you write a code where it shows where East, West, and South are as well?