Skip to content

microbit-mark/MicroPythonCheatsheet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 

Repository files navigation

🐍 Python cheatsheet

Just the basics to get coding using MicroPython on the BBC microbit python.microbit.org

Features

import microbit library

from microbit import *

from microbit import display

import microbit

Buttons

buttona.was_pressed()

buttonb.is_pressed()

accelerometer.was_gesture("shake")

accelerometer.is_gesture("freefall")

accelerometer.get_x()

compass.calibrate()

compass.heading()

compass.get_y()

music.play(music.BIRTHDAY)

tune = ["C4:4", "D4:4", "E4:4", "C4:4", "C4:4", "D4:4", "E4:4", "C4:4",
        "E4:4", "F4:4", "G4:8", "E4:4", "F4:4", "G4:8"]
music.play(tune)

music.pitch(440, 6)

import radio

radio.on()

radio.send('duck')

radio.receive()

pin0.is_touched()

pin1.read_analog()

pin2.write-digital(1)

LED Display (text, image)

display.scroll('hello world')

display.show(Image.DUCK)

temperature()

import neopixel

neopixel.Neopixel(pin0, 10)

neopixel.Neopixel.show()

sleep(500)

 

Coding concepts

Variables

direction = compass.heading()

incoming = radio.receive()

Loops

while True:
     display.show(Image.HEART)
     sleep(10)
     display.show(Image.HEART_SMALL)
    sleep(10)

Conditions

if accelerometer.was_gesture("shake"):
    display.scroll('shake')
elif accelerometer.was_gesture("face down"):
    display.show(Image.HAPPY)
else:
     display.clear()

MicroPython Easter Eggs

import love()

About

Python Cheatsheet for the BBC micro:bit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published