Presentation is loading. Please wait.

Presentation is loading. Please wait.

micro:bit: External Inputs & Outputs

Similar presentations


Presentation on theme: "micro:bit: External Inputs & Outputs"— Presentation transcript:

1 micro:bit: External Inputs & Outputs
Objective: to be able to program the micro:bit to make use of external inputs and outputs.

2 External Inputs & Outputs
The micro:bit has a range of built-in input and output devices. You can do even more with the micro:bit by connecting it other input and output devices. This simple Input/Output board will help you learn how to work with external components. It features 3 LEDs, 3 switches, a button and a speaker.

3 Activity 1 In pairs, look at the program below and write out what you think might happen when it runs on a micro:bit: What would you expect the micro:bit to do?

4 Activity 2 Download and flash the starter program onto your micro:bit. Connect the Input/Output board to the pins on your micro:bit using crocodile clips as shown below:

5 Give an example of how selection is used in the starter program.
Activity 3 In pairs answer the following questions: Question Answer Give an example of how selection is used in the starter program. Does anything happen to the LEDs when the button is pressed? If so what happens?

6 Place a screenshot of your completed code here
Activity 4a The starter program could be considered a basic alarm system, with the Button representing a pressure pad under a mat. However, a single red LED won’t attract much attention, so let’s improve it by making it flash. Place a screenshot of your completed code here Adapt the program to make the red LED flash on and off while the button is pressed and stop when the button is released.

7 Place a screenshot of your completed code here
Activity 4b Connect pin 1 to LED 3 and adapt your program so that the green LED is on when the button is NOT being pressed. This will indicate that the alarm is on but hasn’t been activated. Place a screenshot of your completed code here

8 Place a screenshot of your completed code here
Activity 4c Move the wire that is connected to LED 1 to the Speaker strip on the INPUT/OUPUT board. Change the program so that when the alarm is activated a sound is played instead of flashing the red LED. Tip: to play sound you need to import the music module at the top of your code: This example code will play the tune called BADDY. Place a screenshot of your completed code here Available Sounds: music.DADADADUM music.ENTERTAINER music.PRELUDE music.ODE music.NYAN music.RINGTONE music.FUNK music.BLUES music.BIRTHDAY music.WEDDING music.FUNERAL music.PUNCHLINE music.PYTHON music.BADDY music.CHASE music.BA_DING music.WAWAWAWAA music.JUMP_UP music.JUMP_DOWN music.POWER_UP music.POWER_DOWN

9 Place a screenshot of your completed code here
Activity 4d Move the wire connected to LED 3 to the Switch 1 strip and use a new crocodile lead to connect the 3V pin on the micro:bit to the 3V strip on the Input/Output board. Adapt your program so that the alarm is only active when Switch 1 is closed. There is no longer a need to turn the green LED on when the Button isn’t being pressed. Tip: the example code below will display different images on the micro:bit depending on whether Switch 1 is open or closed. Place a screenshot of your completed code here

10 Challenge Create a new program for a music player.
It should be able to play 5 different tunes. Each time the Button on the Input/Output board is pressed the next tune should be played. When all 5 tunes have been played it should cycle back round to the first tune the next time the Button is pressed. The green LED should be on whenever a tune is playing.


Download ppt "micro:bit: External Inputs & Outputs"

Similar presentations


Ads by Google