Science Oxford Logo

Using inputs

Code Example

from microbit import *
import radio

radio.on()
radio.config(channel=0)

display.show(Image.DUCK)

# begin a forever loop
while True:
    if button_a.was_pressed():
        radio.send('forward 500 1000')
    if button_b.was_pressed():
        radio.send('grab 3')
    if accelerometer.was_gesture('shake'):
        radio.send('left 500 5000')

Look at the syntax and think about where you should add it into your own program - remember that the micro:bit will do your instructions in the order you write them.