0% found this document useful (0 votes)
21 views4 pages

Exploration - Using Micro - Bit Pins (Student) (Physical Computing) (Micro - Bit) (Intro To Micro - Bit)

The document discusses using the pins on a micro:bit to control external LEDs by connecting them to pins 0 and 1. It provides exercises to use digitalWritePin and analogWritePin commands to turn an LED on and off or change its brightness by writing values to the pins. The last section asks the reader to summarize the difference between the two commands and list the pin names.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views4 pages

Exploration - Using Micro - Bit Pins (Student) (Physical Computing) (Micro - Bit) (Intro To Micro - Bit)

The document discusses using the pins on a micro:bit to control external LEDs by connecting them to pins 0 and 1. It provides exercises to use digitalWritePin and analogWritePin commands to turn an LED on and off or change its brightness by writing values to the pins. The last section asks the reader to summarize the difference between the two commands and list the pin names.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

micro:bit Exploration

Using micro:bit Pins

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

1: Pin 0 to resistor - Be sure to pay attention


to the placement of the
2: resistor to long LED leg long LED leg.
3: short LED leg to GND - Wire colors are
irrelevant.

Step 2: Setup Program in MakeCode Editor


1. Head to MakeCode.microbit.org
2. Click on New Project.
3. Develop programs by dragging commands from the center library or by typing them into
the editor yourself.
4. Run programs on your micro:bit device by clicking the Download button.
● Note: All programs in this Exploration should be run on your physical device!

Code #1: Explore the digitalWritePin command


Type the following code into the code editor:
1 pins.digitalWritePin(DigitalPin.P0, 1)

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?

2) What do you think will happen if you change the number 1 to 0?

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

1. What is the difference between the digitalWritePin and analogWritePin commands?

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 Name Second Name

Pin 0

Pin 1

Pin 2

CodeHS | 4

You might also like