# Microbit

Got yourself a Microbit? Awesome! They’re a great way to learn Python!

## Lessons

### Lesson 1: Your first Microbit program

Watch the video and you will:

• Draw emoji’s
• Create your own art work
• Scroll text across the Microbit screen

### Lesson 2: Conditionals

Watch the video and you will:

• Detect button presses
• Keep programs running forever
• Use the accelerometer to detect which way is up

### Lesson 3: Numeric variables and operators

Watch the video and you will:

• Create a counting app
• Create a random number generator
• Create a dice that picks a new number when you shake the Microbit

### Lesson 4: Compound conditionals

Watch the video and you will:

• Create a compass that points north

### Lesson 5: Lists

Watch the video and you will:

• Use the buttons to pick your mood from a list of 9
• Play music such as Beethoven’s 5th symphony

### Lesson 6: For in range()

Watch the video and you will:

• Make another counting app that makes use of the full grid of LEDs and learn about “for loops”.

### Lesson 7: More on conditionals

Watch the video and you will:

• Make a Labryinth style game where you need to keep the marble from falling off the edge of the screen

### Lesson 8: Bluetooth networking

Watch the video and you will:

• Share the love by sending messages to someone else’s Microbit

### Lesson 9: Neopixels

Watch the video and you will:

### Lesson 10: Writing functions and using servos

• Video coming soon…
``````from microbit import *

def servo(pin, degrees=0):
pin.set_analog_period(20)
microseconds = 600 + 1800 * degrees // 180
signal = round(microseconds * 1024 * 50 // 1000000)
pin.write_analog(signal)    # send signal to pin
sleep(500)                  # allow half second for rotation
pin.write_digital(0)        # turn off pin

servo(pin0, 0)
while True:
if button_a.was_pressed():
servo(pin0, 180)        # rotate servo to 180 degree position
if button_b.was_pressed():
servo(pin0, 0)          # rotate servo to 0 degree position
``````

### Lesson 11: Ultrasonic sensors

• Video coming soon…
``````# Ultrasonic
# http://www.teachwithict.com/hcsr045v.html
``````

## Project ideas

• Make a pinball game! - example this is cool!
• LED grid tetris game - example
• LED Neopixel analog clock - example
• LED Neopixel binary clock - example
• LED Neopixel clothing - example, example2
• Fitness step counter using Accelerometer example
• Bluetooth morse code transmitter example (use the buttons to transmit dot/dash/space, convert to letters on the receive end. add a speaker for the beeps?)
• Bluetooth game? - example Battleship
• Bluetooth game show buzzers (one controller and speaker, 3 for game show participants)
• Servo motor controlled cardboard candy dispenser - concept example
• LED Traffic lights - example
• Custom game controller using gyroscope - example
• How clean is my pond - example
• Make a musical instrument (use the gyroscope, accelerometer or touchpad) - example

## Exercises

Display & buttons

1. Make your name scroll across the LED display
2. Display to ask “How do you feel?”. Press button A to show happy emoji, button B to show sad emoji.
3. Create your own image using the Image() function
4. Make your image from the previous fade in after pressing button A, and fade out with button B.
5. Make a ball on the display that bounces when you press button A

Clocks

1. Inspired by this video can you use some NeoPixels to create an LED analog clock?
2. What about creating a binary clock with NeoPixels?

tip: the following are some useful MicroPython time commands…

``````year, month, day, hour, minute, second, ms, dayinyear = utime.localtime()
seconds_since_epoch = utime.time()
milliseconds_powered_up = running_time()
``````

Accelerometer

1. Display the letters “L” or “R” on the display based on which side of the microbit is tilted higher.
2. Make the LEDs light up to indicate the magnitude of acceleration. Moving slow, just a couple of LEDs; moving fast, a lot of LEDs.

Compass

1. Have the microbit display “N”, “S”, “E”, “W” to indicate which way it is facing.
2. Have the microbit turn into a compass where the LED display turns on the LED closest to North.

Thermometer

1. Print the temperature on the display.
2. Use the LEDs to visually display how hot it is… different emoji’s for different temperature.
3. Calculate how much the temperature changes over time. Have the microbit tell you how much the temperature changed each time you press button A, compared to the previous time you pressed button A.

Music

1. Make a song!
2. Turn the microbit into a musical instrument. Change the pitch using the accelerometer.