Educator guide - Unit 2 Algorithms
Educator guide - Unit 2 Algorithms
Science
Unit 2:
Algorithms
Educator guide
makecode.microbit.org
Overview
Unit summary
Introduction to Computer Science Unit 2: Algorithms | 2
This unit introduces students to the four main
components that make up a computer and the concept
of input and output as it relates to programming the
micro:bit. Students will go through two unplugged
activities relating to algorithms and functions that create
a knowledge base for their coding activity and final
project. The coding activity starts with an explanation of Once-a-week timeframe
pseudocode that leads to working with events and event
handlers to program their micro:bit to make faces. The If your class meets only once a week,
project incorporates all the new learning from this unit this unit may take four weeks to
as students create their own fidget cube that responds complete.
to different inputs.
Week 1: Lesson A: How computers
function (only do Crazy Conditionals
Lessons unplugged activity)
Each of the following lessons is intended to be broken Week 2: Lesson B: Code with event
into as many class sessions as needed to complete the handlers
activities.
Weeks 3–4: Lesson C: Fidget cube
Lesson A: How computers function (approx. 45-60 min) (approx. 90-120 min)
Lesson B: Code with event handlers (approx. 60-75 min)
Lesson C: Fidget cube (approx. 60-120 min)
Learning goals
During this unit, students will:
Understand the four components that make up a computer and their functions.
Understand that the micro:bit takes input, and after processing the input, produces output.
Learn the variety of different types of information the micro:bit takes in as input.
Apply this knowledge by creating a micro:bit program that takes input and produces an output.
1B-CS-01 Describe how internal and external parts of computing devices function to form a system.
1B-CS-02 Model how computer hardware and software work together as a system to accomplish tasks.
1B-AP-10 Create programs that include sequences, events, loops, and conditionals.
1B-AP-17 Describe choices made during program development using code comments, presentations, and
demonstrations.
2-AP-10 Use flowcharts and/or pseudocode to address complex problems as algorithms
Required skills
To lead the activities in this unit successfully, you need to be able to:
Recommended resources
If you would like additional support to master the concepts and skills covered in this unit, review the
following resources.
Outline
Section 1: Understanding components of a computer
Section 3: Wrap-up
Review: Review learning goals, what the students accomplished, and preview next lesson
Exit ticket: Distribute and collect the exit ticket to assess learning
Although the student workbooks have space for note-taking, consider having extra paper (or index
cards) available in case any students need more space.
Print one exit ticket per student (printable versions are found in the assessment guide).
Educator notes
1. Write the “Do now” on the board for students to think about as they arrive:
What is a computer?
Answer: Responses will vary.
2. Introduce the lesson and learning goals.
3. Discuss their responses to the “Do now.”
What is a computer?
Storage (also referred to as the computer “hard drive”): This is the computer’s long-term memory,
where it can store information even when power is turned off. Can you think of examples of things
that are stored in our long-term memory? Things we never forget?
3. Inputs: This is how a computer takes in information from the world. In humans, our input comes in
through our senses, such as our ears and eyes. What are some computer Inputs? Keyboard, mouse,
touchscreen, camera, microphone, game controller, scanner, etc.
4. Outputs: This is how a computer displays or communicates information. As humans, we communicate
information by using our mouths when we talk. What are some examples of communication that don’t
involve talking? Blushing, sign language. What are some examples of computer outputs?
Monitor/screen, headphones/speakers, printer, etc.
Now, let’s look at our micro:bit (Reference the micro:bit features as needed at
microbit.org/guide/features):
Ask students:
Can you find the Processor? Answer: On the back of the micro:bit, just below the Bluetooth and radio
antenna.
How much memory does the micro:bit have? Answer: 16K, which is smaller than many files on your
computer!
Can you locate the following Inputs? Answer: Buttons (on board), Pins (at base),
Accelerometer/Compass.
All computers need electricity to power them. There are three ways to power your micro:bit:
Connecting the micro:bit to a computer through the USB port at the top
Connecting a battery pack to the battery connector
Through the 3V Pin at the bottom (not the recommended way to power your micro:bit)
On the top left corner, you may notice that your micro:bit has a Bluetooth antenna. This means your
micro:bit can communicate and send information to other micro:bits. We will learn more about this feature
in Unit 10: Radio communication.
Educator notes
An unplugged activity is an activity that takes place away from the computer—in other words,
“unplugged” from technology. This introduces new concepts in a fun way that gets students up and
moving, often reacting and interacting with other students face to face while playing a game or
completing a challenge. Unplugged activities allow students to practice concepts away from devices
so that when they move to coding activities, they have already walked through and thought about
the concepts on their own.
Materials
Strips of paper, each with one conditional statement on it (prepared in advance for the second
activity)
1. What are the four main components that make up any computer?
Answer: The processor, the memory, the inputs and the outputs
2. How many programmable buttons are on the micro:bit?
Answer: Two
Objective
Overview
For this activity, the students will work in pairs, Player A and Player B. The pairs will take turns being the
function machine for their partner who will be providing input to be processed. The goal is for Player A to
figure out what function (or bit of processing) Player B is using in the fewest number of rounds of
input/output possible.
Player B
Player A
Add 8
Subtract 6
Multiply by 3
Divide by 2
Share the examples of the difficulty level of functions students should use and direct students on how you
would like them to record their work.
1. Player B decides on a mathematical function (or bit of processing) that will be done on whatever input
they receive from Player A. Then they will write it down and set it aside, out of sight of Player A.
2. Player A then gives Player B a number to process.
3. Player B processes the number and returns an output to Player A.
4. Player A can then state what function (or bit of processing) they think Player B is using on the input to
produce the given output. One try per round of input/output.
If Player A states the correct function, Player B confirms that it is correct by showing the previously
hidden function and the players switch roles and start the game over.
If Player A does not guess correctly, Player A provides another input that Player B processes and
provides an output for.
5. After each student has had at least one chance to be the function machine, play more rounds as time
permits.
Objective
This is a fun, interactive exercise to introduce conditionals and event handlers as computer processing.
Read through the entire activity and adjust as needed for your students and classroom.
Process
1. Hand out the conditional strips to the number of students as noted in the table below, and following
these guidelines:
Some of the same conditionals can be given to multiple students, while other conditionals are to be
given to just one student.
Besides the ‘BEGIN’ and ‘STOP’ conditional, give at least two other conditionals to each student. A
lesson from this is that it is challenging for a student to keep track of a lot of different conditionals,
though not so for a computer!
Except for the first ‘BEGIN’ conditional, hand out the conditionals print side down.
Note: Technically, these conditionals are all event handlers because the students are simply waiting for
a specific event to trigger them into action.
2. Unless instructed otherwise, students do not speak or make noise during this activity.
3. Start the activity by writing BEGIN on the whiteboard.
4. As the activity progresses, trigger the six conditionals multiple times, e.g., say “popcorn,” write on the
whiteboard with a green marker and/or snap your fingers multiple times, etc.
5. When you want to wrap up the activity, trigger the final seven conditionals by picking up a book, then
the remaining triggers, e.g., open/close the classroom door, turn the lights on/off, sharpen a pencil.
Extensions/variations
Add AND, OR, AND/OR statements to the conditionals.
Create nested IFs.
Let students create the IFs.
Relate this activity to a system and have students create the conditionals that would end in a
product of some kind or the completion of some task.
Section 3: Wrap-up
Educator notes
1. Review learning goals with students, what they accomplished, and preview the next lesson.
2. Distribute and collect the exit ticket.
Reflection
Consider if there were any concepts of the lesson or exit ticket students struggled with that you
might want to reinforce or re-teach at the beginning of the next lesson.
Consider what aspects of the lesson students found engaging and how you might emphasize those
in the next lesson.
Follow up on any questions that arose during the lesson that require additional research on your
part.
Lesson A assessments
“Do now”
What is a computer?
Answer: Responses will vary
What are the four main components The processor, the memory, the inputs and the outputs
that make up any computer?
Exit ticket
Format: Printed half-page handout for students to complete and turn in as they leave class. (Printer-
friendly versions are found in the assessment guide.)
Questions Answers
Outline
Section 1: Introduce the lesson
Section 3: Wrap-up
Review: Review learning goals, what the students accomplished, and preview next lesson
Educator notes
1. Write the “Do now” question on the board for students to think about as they arrive:
Write down two examples of computer input and two examples of computer output
Answer: Responses will vary
2. Introduce the lesson and learning goals.
3. Discuss their responses to the “Do now.”
Educator notes
1. Use your established equipment safety procedures for distributing and using the hardware and
ensure students are properly set up to begin coding in MakeCode and micro:bit.
2. Follow the instructions to lead the birdhouse activity. Do the activity on your device connected to
the projector or presentation screen and have students follow along as you complete each step. If
you don’t have a projector or screen, move throughout the room between steps to check for
understanding and help facilitate the activity.
3. Pause after each step to check for understanding and take questions as needed.
4. After the activity, distribute the quiz (see the assessment guide for a printable format).
5. If you have time during class, consider reviewing the quiz answers as a group activity.
Each unit contains a micro:bit activity, which we informally refer to as a “birdhouse” activity, after
the innumerable wooden birdhouses so many of us made in wood shop as a way to master basic
skills. The activity is an example that walks students step by step through building a project that
demonstrates that unit’s topic. By the time students finish the activity, they will have written code
that they can use in a different project of their own design.
In this activity, we will discover how to use the micro:bit buttons as input devices and write code that will
make something happen on the screen as output. We will also learn about pseudocode, the MakeCode
tool, event handlers, and commenting code.
Pseudocode
What do you want your program to do? The first step in writing a computer program is to create a plan for
what you want your program to do. Write out a detailed step-by-step plan for your program. Your plan
should include what type of information your program will receive, how this input will be processed, what
output your program will create, and how the output will be recorded or presented. Your writing does not
need to be written in complete sentences nor include actual code. This kind of detailed writing is known as
pseudocode. Pseudocode is like a detailed outline or rough draft of your program. Pseudocode is a mix of
natural language and code.
For the program we will write, the pseudocode might look like this:
Now that you have a plan for your program in the form of pseudocode, let’s start creating the real program
in Microsoft MakeCode. Remember, the MakeCode tool is called an IDE (Integrated Development
Environment) and is a software application that contains everything a programmer needs to create,
compile, run, test, and even debug a program.
Event handlers
When you start a new project, there will be two blue blocks, ‘on start’ and ‘forever’, already in the coding
Workspace. These two blocks are event handlers.
In programming, an event is an action done by the user, such as pressing a key or clicking a mouse button.
An event handler is a routine that responds to an event. A programmer can write code telling the computer
what to do when an event occurs.
Tool tips
2. Block descriptions: Hover over any block until a hand icon appears and a small text box will pop up
telling you what that block does. You can try this now with the ‘on start’ and ‘forever’ blocks.
Help: You can also right-click on any block and select Help to open the reference documentation.
Clear screen
4. Looking at our pseudocode, we want to be sure to start a program with a clear screen. We can do this
by going to the Basic menu, selecting … more, and then a ‘clear screen’ block.
6. Go ahead and drag the ‘clear screen’ block into the ‘on start’ block. Now the block is no longer grayed
out, indicating that it will run when the event occurs—i.e., the program starts.
We now have a working program running on the micro:bit simulator! As you write your program,
MakeCode will automatically compile and run your code on the simulator. The program doesn’t do much at
this point, but before we make it more interesting, we should name our program and save it.
7. On the bottom left of the application window, to the right of the Download button, is a text box in which
you can name your program. After naming your program, select the save button to save it.
Important: Whenever you write a significant piece of code or just every few minutes, you should save your
code. Giving your code a meaningful name will help you find it faster and let others know what your
program does.
Now to make our program a bit more interesting by adding two more event handlers.
8. From the Input menu, drag two ‘on button A pressed’ blocks to the coding Workspace. Notice that the
second block is grayed out. This is because, right now, they are the same block, both “listening” for the
same event ‘on button A pressed’.
9. Leave the first block alone for now, and using the drop-down menu within the second block, change the
A to B. Now this block will no longer be grayed out, as it is now listening for a different event, ‘on
button B pressed’.
Now we can use our LED lights to display different images depending on what button the user presses.
10. From the Basic Toolbox, drag two ‘show leds’ blocks to the coding Workspace. Place one ‘show leds’
block into the ‘on button A pressed’ event handler and the second ‘show leds’ block into the ‘on button
B pressed’ event handler.
11. Select the individual little boxes in the ‘show leds’ block that is in the ‘on button A pressed’ event
handler to create the image of a happy face. Select the individual little boxes in the ‘show leds’ block
that is in the ‘on button B pressed’ event handler to create the image of a sad face.
Feel free to play around with turning LEDs on or off in the ‘show leds’ blocks until you get the images you
want.
It is good practice to add comments to your code. Comments can be useful in a number of ways.
Comments can help you remember what a certain block of code does and/or why you chose to program
something the way you did. Comments also help others reading your code to understand these same
things.
Select the question mark icon again to close the comment box when you are done.
Select the question mark icon whenever you want to see your comment again or to edit it.
In JavaScript, you can add a comment by using two forward slashes, then typing your comment. The two
forward slashes tell JavaScript that the following text (on that same line) is a comment.
Cleaning up!
13. Clean up your coding Workspace before you do a final save. What does this mean?
It means that only the code and blocks that you are using in your program are still in the workspace.
Remove (delete) any other blocks that you may have dragged into the coding workspace as you
were experimenting and building your program.
Section 3: Wrap-up
Educator notes
1. Review learning goals with students, what they accomplished, and preview the next lesson.
2. Use your established equipment safety procedures for collecting and storing the hardware.
Assessment
Review and grade the quiz (unless you reviewed with students in class).
Reflection
Consider if there were any concepts of the lesson or quiz students struggled with that you might
want to reinforce or re-teach at the beginning of the next lesson.
Consider what aspects of the lesson students found engaging and how you might emphasize those
in the next lesson.
Follow up on any questions that arose during the lesson that require additional research on your
part.
“Do now”
Write down two examples of computer input and two examples of computer output.
Answer: Responses will vary
Quiz
Format: Printed full-page handout for students to complete during class. (Please see the assessment guide
for printer-friendly versions to distribute to students.)
Questions Answers
2. What is the difference between RAM and hard drive a. RAM is the computer’s short-term
memory? memory and the hard drive is where the
computer stores its long-term memory.
a. RAM is the computer’s short-term memory and
the hard drive is where the computer stores its
long-term memory.
b. The hard drive is where the computer stores its
short-term memory and RAM is the computer’s
long-term memory.
c. RAM is used for programming and the hard drive
memory is for storage.
d. Hard drive memory is for storing files and RAM is
used for processing inputs.
Outline
Section 1: Introduce the lesson
Section 3: Wrap-up
Exit ticket: Students complete a Reflection Diary entry for their project
Review: Review the learning goals, what students accomplished, and preview next unit
Email the Reflection Diary questions for the project to students or post it in a shared drive so
students can send their responses to you electronically.
Ensure you have the needed hardware for each student (or pair):
Computer, laptop, or tablet
micro:bit
Micro-USB cable
Battery pack (with two AAA batteries)
Although the student workbooks have space for note taking and drawing, consider having extra
paper available in case any students need more design space.
Educator notes
1. Write the “Do now” on the board for students to think about as they arrive:
Do you ever fidget? If so, what kinds of things do you fidget with regularly?
Answer: Responses will vary
2. Introduce the learning goals and discuss responses to the “Do Now.”
3. Review any themes that students are struggling with from the quiz results unless you covered
this at the end of the last lesson.
Educator notes
1. Use your established equipment safety procedures for distributing and using the hardware and
ensure students are properly set up to begin coding in MakeCode and micro:bit.
2. Follow the instructions to explain the expectations for their project, provide ideas, examples, and
the scoring rubric, which are also in the student workbook.
3. Encourage students who finish early or need an extra challenge to try one or more of the mod
ideas.
4. After the activity, consider having students share their projects in pairs, small groups, or with the
rest of the class as time allows.
5. Be sure to allow enough time for students to complete their Reflection Diary entry in the next
section.
Objective of projects
Open-ended projects are opportunities to apply the concepts and skills students have developed in
an original and creative way. Students will work on their projects in a “collaboratively independent”
way, which means each student is responsible for turning in his or her own project but are
encouraged to work together and help each other while doing so. Some form of reflection is an
important part of documenting the learning that has taken place.
Show students the funny fidget cube video (5:09) in the presentation deck.
This project is to make a fidget cube out of the micro:bit and create a unique output for each of the
following inputs:
on button A pressed
on button B pressed
on button A+B pressed
on shake
See if you can combine a maker element similar to what you created in Unit 1 by providing a holder for the
micro:bit that holds it securely when you press one of the buttons.
Discussion questions
Remind students that a computing device has a number of inputs and outputs. The code that we write
processes input by telling the micro:bit what to do when various events occur.
Project expectations
Follow the design thinking approach and make sure your project meets the required specifications:
Assessment
1 2 3 4
elements
Inputs Fewer than two At least two At least three At least four different
different inputs different inputs different inputs inputs are
are successfully are successfully are successfully successfully
implemented. implemented. implemented. implemented.
Outputs Fewer than two At least two At least three At least four different
different outputs different outputs different outputs outputs are
are successfully are successfully are successfully successfully
implemented. implemented. implemented. implemented.
Uses meaningful
comments in code
Section 3: Wrap-up
Educator notes
1. Explain the expectations and scoring rubric for the Reflection Diary entry for their project (also in
the student workbook).
2. Review the learning goals, what students accomplished, and preview the next unit.
3. Use your established equipment safety procedures for collecting and storing the hardware.
Expectations
What problem did you solve, or why did you decide to create this project?
What kind of input and output did you decide to use?
What does your program do? Describe how your program works (what the cause and effect are).
Include at least one screenshot of your program working.
Publish your MakeCode program and include the URL.
Assessment
1 2 3 4
elements
Diary entry Diary entry is Diary entry is Diary entry is Diary entry
missing three or missing two of the missing one of the addresses all
more of the required elements. required elements. elements.
required elements.
Assessment
Review and grade the projects and diary entries. (A full page, printer-friendly version of the project
scoring rubric is available in the assessment guide.)
Reflection
Consider if there were any concepts of the lesson, project, or diary entries students struggled with
that you might want to reinforce or re-teach before or at the beginning of the next unit.
Consider what aspects of the lesson students found engaging and how you might emphasize those
in the next unit.
Follow up on any questions that arose during the lesson that require additional research on your
part.
“Do now”
Do you ever fidget? If so, what kinds of things do you fidget with regularly?
Answer: Responses will vary
What problem did you solve, or why did you decide to create this project?
What kind of input and output did you decide to use?
What does your program do? Describe how your program works (what the cause and effect are).
Include at least one screenshot of your program working.
Publish your MakeCode program and include the URL.