Exploration - Using Micro - Bit Pins (Student) (Physical Computing) (Micro - Bit) (Intro To Micro - Bit)
Exploration - Using Micro - Bit Pins (Student) (Physical Computing) (Micro - Bit) (Intro To Micro - Bit)
Corresponding Material
1.4- Variables & Naming Rules
Discussion
We have now learned a few different ways to control the LEDs that exist on our built-in
grid, but there are many more components we can control with our micro:bit! Our device has
many built-in pins that can be used to connect and control external components. If you look at
the bottom of your micro:bit, you’ll see 5 holes, labeled 0, 1, 2, 3V, and GND. In this exploration,
we will use our micro:bit in circuits in order to connect external LEDs.
Needed Materials
(1) Micro:bit (1) USB cord (3) alligator clip wire (1) LED (1) resistor
Class Exercise
Step 1- Build Circuit: Follow the diagram below to build a circuit with an external LED.
Circuit Diagram Connections Notes
Download the code to your micro:bit and answer the following questions.
CodeHS | 1
1) What do you see when you run the code on your micro:bit?
Go into the code editor and add two more lines to test setting DigitalPin.P0 to 0. Download
this code to your micro:bit.
1 pins.digitalWritePin(DigitalPin.P0, 1)
2 basic.pause(1000)
3 pins.digitalWritePin(DigitalPin.P0, 0)
3) Was your hypothesis correct? What happened when you ran the code?
4) What does a value of 0 mean when using an LED? What does a value of 1 mean? Can any
other values be used?
5) Can you blink the external LED every second until the micro:bit is disconnected from a power
source? Try out some commands in the editor and once you’ve completed the task, copy the
code below:
1
2
3
4
5
6
CodeHS | 2
Code #2: Explore the analogWritePin command
Type the following code into the code editor:
1 basic.forever(function () {
2 pins.analogWritePin(AnalogPin.P0, 0)
3 basic.pause(2000)
4 pins.analogWritePin(AnalogPin.P0, 500)
5 basic.pause(2000)
6 pins.analogWritePin(AnalogPin.P0, 1000)
7 basic.pause(2000)
8 })
Download the code to your micro:bit or run and answer the following questions.
1) What do you see when you run the code on your micro:bit?
2) What is the highest brightness value that can be used? How did you find this out?
3) What do you think would need to change in our program if the LED were connected to Pin 1
instead of Pin 0?
Edit your circuit to connect the LED to pin 1 instead of pin 0 as in the diagram below:
CodeHS | 3
4) Test your hypothesis out on your device. Were you correct? What needed to be altered in your
code?
5) Can you write a program that will blink the external LED through pin 1 between
half-brightness and full-brightness every second forever? Try out some commands in the editor
and once you’ve solved the task, copy the code below:
1
2
3
4
5
6
Conclusion Questions
2. Write the names for all the pins we can use to connect external components to our
micro:bit. (Note: each pin has 2 names depending on the command being used!)
Pin 0
Pin 1
Pin 2
CodeHS | 4