Professional Documents
Culture Documents
UNIT 2: ALGORITHMS
Educator guide
makecode.microbit.org
CONTENTS
Overview .......................................................................................................................................................................................................................... 2
Unit summary ............................................................................................................................................................................................................. 2
Lessons ......................................................................................................................................................................................................................... 2
Learning goals............................................................................................................................................................................................................ 2
CSTA K-12 computer science standards ........................................................................................................................................................... 2
Required educator preparation ................................................................................................................................................................................ 3
Preparing to lead the unit ...................................................................................................................................................................................... 3
Required skills ............................................................................................................................................................................................................ 3
Recommended resources....................................................................................................................................................................................... 3
Lesson A: How computers function......................................................................................................................................................................... 4
Lesson plan ................................................................................................................................................................................................................. 4
Outline .......................................................................................................................................................................................................................... 4
Before the lesson ...................................................................................................................................................................................................... 4
Lesson details ............................................................................................................................................................................................................. 5
After the lesson .......................................................................................................................................................................................................11
Lesson A assessments ...........................................................................................................................................................................................11
Lesson B: Code with event handlers......................................................................................................................................................................12
Lesson plan ...............................................................................................................................................................................................................12
Outline ........................................................................................................................................................................................................................12
Before the lesson ....................................................................................................................................................................................................12
Lesson details ...........................................................................................................................................................................................................12
After the lesson .......................................................................................................................................................................................................20
Lesson B assessments............................................................................................................................................................................................21
Lesson C: Fidget cube ................................................................................................................................................................................................23
Lesson plan ...............................................................................................................................................................................................................23
Outline ........................................................................................................................................................................................................................23
Before the lesson ....................................................................................................................................................................................................23
Lesson details ...........................................................................................................................................................................................................24
After the lesson .......................................................................................................................................................................................................27
Lesson C assessments ...........................................................................................................................................................................................27
Lessons
Each of the following lessons are intended to be broken into as many class sessions as needed to complete the activities.
Lesson A: How computers function (approximately 45-60 minutes)
Lesson B: Code with event handlers (approximately 60-75 minutes)
Lesson C: Fidget cube (approximately 60-120 minutes)
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.
Required skills
To lead the activities in this unit successfully, you need to be able to:
Explain the features of the micro:bit.
Use the following features and blocks in MakeCode:
▪ Start and name a new project.
▪ Download a project to the micro:bit.
▪ Tool tip functions, like right-clicking a block for Help, deleting blocks, adding comments, etc.
▪ ‘on start’, ‘show leds’, and ‘clear screen’ blocks from the Basic Toolbox.
▪ ‘on button pressed’ block from the Input Toolbox.
Recommended resources
If you would like additional support to master the concepts and skills covered in this unit, review the following resources.
▪ Learn more about basic micro:bit functions and actions at makecode.microbit.org/reference/basic.
▪ Learn more about micro:bit inputs at makecode.microbit.org/reference/input.
▪ Learn more about on start blocks at makecode.microbit.org/blocks/on-start.
▪ Review micro:bit safety advice at microbit.org/guide/safety-advice/.
▪ Search the micro:bit support knowledge base at support.microbit.org/support/home.
Outline
Section 1: Understanding components of a computer
Section 3: Wrap-up
Review Review the learning goals, what students accomplished, and preview the next lesson
Exit ticket Distribute and collect the exit ticket to assess learning
Educator notes
1. Write the “Do now” questions 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.”
1. The Processor – this is usually a small chip inside the computer, and it’s how the computer processes and transforms
information. Has anyone heard of the term “CPU”? CPU stands for Central Processing Unit. You can think of the
processor as the Brains of the computer - the faster the processor, the more quickly the computer can think.
2. The Memory – this is how the computer remembers things. There are two types of memory:
▪ RAM (random access memory) - you can think of this as the computer’s short-term memory, things that are
stored here will disappear when the computer is turned off. Can you think of examples of things that are stored in
our short-term memory? Things that you forget after you go to sleep?
▪ 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/):
Note: Though not pictured, the Light Sensor is located on the LED lights.
Introduction to Computer Science 2: Algorithms | 6
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.
▪ Where are the Outputs? Answer: LED lights and Pins
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
1. Follow the instructions to lead the two unplugged activities.
2. After both activities, use the knowledge check questions to confirm understanding.
Materials
▪ Index cards (optional for the first activity)
▪ Strips of paper, each with one conditional statement on it (prepared in advance for the second activity)
Objective
To guess the mathematical function based on how an input is processed.
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.
Here are the roles:
Player B
▪ Privately determines a mathematical function to apply to a numeric input
▪ Processes the input from Player A using the function
▪ Provides the output
Player A
▪ Provides a number for the input to Player B
▪ Guesses the function based on the output received from Player B
Examples of easier functions
▪ Add 8
▪ Subtract 6
▪ Multiply by 3
▪ Divide by 2
Examples of more difficult functions
▪ Multiply by 2 and then subtract 1
▪ Square the input
▪ Return 20% of the input
Options for students to record their work
▪ The student workbooks have a table to record inputs and outputs, or
▪ Provide index cards so Player A can write each input on one side of an index card, hand the card to Player B, who
then writes the corresponding output on the other side of the card.
Process
Share the examples of the difficulty level of functions students should use and direct students 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 she receives
from Player A. Then writes it down and sets 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) she thinks 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.
Introduction to Computer Science 2: Algorithms | 8
Unplugged activity 2: Crazy conditionals
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.
Seven conditionals for one student: These will be triggered only once and set in motion the spelling of STOP on the
whiteboard.
Extensions/variations
▪ Add AND, OR, AND/OR statements to the conditionals.
▪ Create nested IF’s.
▪ Let students create the IF’s.
▪ Relate this activity to a system and have the students create the conditionals that would end in a product of some
kind or the completion of some task.
Section 3: Wrap-up
Slides 9-10
Reflection
Consider if there were any concepts of the lesson or exit ticket students struggled with that you might want to
reinforce or reteach 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”
Format: Written on the board at the start of the lesson.
▪ What is a computer? Answer: Responses will vary
What are the four main components that make up any The processor, the memory, the inputs and the
computer? outputs
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
Name a real-life event from today’s class that caused an Responses will vary
action.
Outline
Section 1: Introduce the lesson
Section 3: Wrap-up
Review Review learning goals, what the students accomplished, and preview next lesson
Lesson details
Section 1: Introduce the lesson
Slides 11-12
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.
Tips
Some students will finish the activity more quickly than others. Those students can then be a helpful resource for their
classmates, or they can challenge themselves by modifying, or “modding” the activity to do something different. We
have provided examples and suggestions at the end of many of these activities, and feel free to suggest your own (or
encourage your students to come up with their own ideas!)
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:
▪ Start with a blank screen
▪ Whenever the user presses button A, display a happy face
▪ Whenever the user presses button B, display a sad face
Microsoft MakeCode
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.
In Microsoft MakeCode, start a new project.
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
Experiment with the following options.
1. 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.
2. Help - You can also right-click on any block and select Help to open the reference documentation.
3. Deleting blocks - Click on the ‘forever’ block and drag it left to the Toolbox area. You should see a garbage can icon
appear. Let go of the block and it should disappear. You can drag any block back to the Toolbox area to delete it from
the coding Workspace. You can also remove a block from the coding Workspace by:
▪ Hovering over the block, right-clicking, and selecting Delete Block, or
▪ Selecting the block and then pressing the “delete” key on your keyboard (or command-X on a mac).
Clear screen
Looking at our pseudocode, we want to make sure to start a program with a clear screen. We can do this by going to the
Basic menu - more and choosing a ‘clear screen’ block.
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.
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 from a list of programs and will let others know what your
program does.
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’.
Show LEDs
Now we can use our LED lights to display different images depending on what button the user presses.
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.
▪ Click on the question mark icon again to close the comment box when you are done.
▪ Click on 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!
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.
Introduction to Computer Science 2: Algorithms | 19
▪ 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
Slides 17-18
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.
Lesson B assessments
“Do now”
Format: Written on the board at the start of the lesson.
▪ 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
1. What is a computer processor? d. A small chip inside the computer that the
a. Where the computer stores its memory computer uses to process and transform
b. The face of the micro:bit information
c. The area of a MakeCode project that shows how a
program looks when run on the micro:bit
d. A small chip inside the computer that the computer uses
to process and transform information
2. What is the difference between RAM and hard drive memory? a. RAM is the computer’s short-term memory
a. RAM is the computer’s short-term memory and the hard and the hard drive is where the computer
drive is where the computer stores its long-term memory stores its long-term memory
b. The hard drive is where the computer stores its short-
term memory and RAM is the computer 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
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 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.
Discussion questions
Use the following questions to help get students started:
▪ Do any of your students fidget?
▪ What kinds of things do they fidget with? Spinning pens, fidget spinners, rings, coins?
▪ There are many different versions of fidget cubes available now. Do any students have any?
▪ Have they seen them before?
▪ What are the types of fidget activities?
▪ If students could add or modify features of the fidget cube, what would they choose to do?
▪ What would make the ultimate fidget cube?
Remind students that a computing device has a number of inputs, and a number of outputs. The code that we write
processes input by telling the micro:bit what to do when various events occur.
Project mods
▪ Add more inputs and more outputs - use more than four different types of input.
▪ Try to use other types of output (other than LEDs) such as sound!
Assessment elements 1 2 3 4
Inputs Fewer than two At least two At least three At least four different
different inputs are different inputs are different inputs are inputs are successfully
successfully successfully successfully implemented.
implemented. implemented. implemented.
Outputs Fewer than two At least two At least three At least four different
different outputs are different outputs are different outputs are outputs are successfully
successfully successfully successfully implemented.
implemented. implemented. implemented.
micro:bit program micro:bit program micro:bit program micro:bit program micro:bit program:
lacks all of the lacks two of the lacks one of the
▪ Uses event handlers
required elements. required elements. required elements.
in a way that is
integral to the
program
▪ Compiles and runs
as intended
▪ Uses meaningful
comments in code
Section 3: Wrap-up
Slides 23-25
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
Write a reflection of about 150–300 words, addressing the following points:
▪ 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 elements 1 2 3 4
Diary entry Diary entry is Diary entry is Diary entry is Diary entry addresses all
missing three or missing two of the missing one of the elements.
more of the required elements. required elements.
required elements.
Reflection
Consider if there were any concepts of the lesson, project or diary entries students struggled with that you might want
to reinforce or reteach 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.
Lesson C assessments
“Do now”
Format: Written on the board at the start of the lesson:
▪ Do you ever fidget? If so, what kinds of things do you fidget with regularly? Answer: Responses will vary