← Back to Library
Lesson PlanFreeEN

CyberPi: Colour Mixer

In this lesson, students will be introduced to variables to create a CyberPi Colour Mixer. This program will use the joystick and buttons to control the R, G, B colour values of all of the on-board LEDs. Then, students will use conditional statements to ensure that the R, G, B values do not go out-of-range.

Gr. 6–8
CyberPi: Colour Mixer

Lesson

Overview

Description

In this lesson, students will be introduced to variables to create a CyberPi Colour Mixer. This program will use the joystick and buttons to control the R, G, B colour values of all of the on-board LEDs. Then, students will use conditional statements to ensure that the R, G, B values do not go out-of-range.

Objectives

  • Use a variable to store a value.

  • Change a variable based on user input.

  • Write a program in mBlock that executes a program if a condition is met.

Before the Lesson

Preparation

For the teacher and students:

Example program(s): CyberPi – Lesson 7 – Color Mixer

Review

Warm Up

Conditional Statements Game

1. Play a game similar to Simon Says with your class to demonstrate conditional statements. With your students, read each statement below and have the students follow the command. (Feel free to write your own commands for your students.) 

  • "IF" your name has the letter “S” in it, "THEN" raise your hand.

  • "IF" you have a pet cat, "THEN" clap your hands.

  • "IF" you play a sport, "THEN" stomp your feet.

  • "IF" you are wearing socks, "THEN" touch your feet.

  • "IF" your favourite ice cream is chocolate, "THEN" say “Yum.”

2. Share with students that these commands are examples of conditional statements. In programming, conditional statements are used to perform specific actions if a condition is true.

Direct Instruction

Tour of mBlock 5

1. Open the mBlock software or mBlock 5 Web version.

2. Introduce students to the following key areas of the software interface:

Connect the CyberPi

3. Plug the CyberPi into the computer using the included cable. The CyberPi should boot up and the screen will display either the last program uploaded or the Home menu.

4. On the "Devices" tab in mBlock, click the "Add" button. Select CyberPi and click "Ok".

5. Click the "Connect" button. Then, select the USB port and click "Connect".

6. If connected successfully, the button will change to "Disconnect".

Guided Practice

Hands On

Storing Data with a Variable

1. Discuss the following definition with the students:

2. Review the following challenge and pseudocode with the students:

3. To program this project, a variable must be used to store the value of each of the LEDs. The variables will start at zero (0) when the CyberPi starts and will be adjusted using the joystick or buttons.

4. Open the mBlock 5 software or mBlock 5 Web version. Add the CyberPi in the Devices tab and connect in Live mode.

5. Go to the Variables section of the Block Area. Click the Make a Variable button.

6. Name the new variable redValue and leave For all sprites selected.

7. Introduce students to the following new blocks which are now available in the Variables section:

8. Instruct students to build the following scripts and test the program to observe the joystick up/down controls increasing the red value of all of the LEDs:

Using a Conditional Statement

9. Remind students that the R, G, B values have a range of 0 to 255. With the program above, the redValue variable can be changed to a value that falls outside of that range. We can use conditional statements to control the minimum and maximum values. Instruct students to modify the code and add the following conditional statements to the program:

10. Explain to the students how the conditional statements do not allow the "redValue" to ever be greater than 255 or less than 0.

Independent Practice

Try It

Completing the Program

1. Instruct students to finish the program based on the pseudocode provided earlier in the lesson. The following is an example of a completed program:

2. Students may find it helpful to add the following script inside the forever loop to see the values of the variables on the CyberPi display:

Extension

  • Have students add a title and instructions to the project.

  • Have students create a variable for the LEDNumber and use the middle joystick button to control which LED is being changed.

Wrap Up

Wrap-Up & Quick Check

Variable Review

Discuss with students how variables are used to store information in a variety of computing devices and applications. Discuss the following examples with students:

  • Fitness trackers stores the number of steps.

  • Automobiles (with a digital display) stores the number of miles driven.

  • Mobile devices store the battery level and reports it as a percentage.

  • Store shopping cards store the number of visits until you earn a reward.

  • Video games store health, lives and scores.

Downloadable Material

Example Program

Educational Standards

CSTA

CSTA

  • 2-CS-02: Design projects that combine hardware and software components to collect and exchange data.

  • 2-AP-11: Create clearly named variables that represent different data types and perform operations on their values.

  • 2-DA-07: Represent data using multiple encoding schemes.

Alberta - Grade 6-8 - CTF

Grade 6-8

CTF

- Planning, creating, appraising and communicating in response to challenges. 

- Working independently and with others while exploring careers and technology.

British Columbia - Grade 6-8 - ADST

Grade 6-7

ADST

• Generate potential ideas and add to others’ ideas 

• Identify and evaluate the skills and skill levels needed, individually or as a group, in relation to a specific task, and develop them as needed 

• Select, and as needed learn about, appropriate tools and technologies to extend their capability to complete a task 

Grade 8

ADST

• Generate potential ideas and add to others’ ideas 

• Make a plan for production that includes key stages, and carry it out, making changes as needed

• Identify and evaluate the skills and skill levels needed, individually or as a group, in relation to a specific task, and develop them as needed

• Select, and as needed learn about, appropriate tools and technologies to extend their capability to complete a task

Manitoba - Grade 6-8 - Science

Grade 6

Science (Overall Skills and Attitudes)

  • 6-0-4a: Carry out procedures that comprise a fair test. Include: controlling variables; repeating measurements to increase accuracy and reliability.

  • 6-0-4c: Work cooperatively with group members to carry out a plan, and troubleshoot problems as they arise.

Grade 7

Science (Overall Skills and Attitudes)

  • 7-0-4a: Carry out procedures that comprise a fair test. Include: controlling variables, repeating experiments to increase accuracy and reliability

  • 7-0-4c: Work cooperatively with team members to carry out a plan, and troubleshoot problems as they arise.

Grade 8

Science (Overall Skills and Attitudes)

  • 8-0-4a: Carry out procedures that comprise a fair test. Include: controlling variables, repeating experiments to increase accuracy and reliability

  • 8-0-4c: Work cooperatively with team members to carry out a plan, and troubleshoot problems as they arise.

New Brunswick - Grade 6-8 - Science

Grade 6-8

Science (Attitude Outcome)

  • 425: show a continuing curiosity and interest in a broad scope of science-related fields and issues

  • 430: persist in seeking answers to difficult questions and solutions to difficult problems

  • 431: work collaboratively in carrying out investigations, as well as in generating and evaluating ideas

Newfoundland & Labrador - Grade 6-8 - Science

Grade 6-8

Science

  • GCO: Skills - Students will develop the skills required for scientific and technological inquiry, for solving problems, for communicating scientific ideas and results, for working collaboratively, and for making informed decisions.

Nova Scotia - Grade 6-8 - Mathematics & ICT/Technology

Grade 6

Mathematics

N09 Students will be expected to explain and apply the order of operations, excluding exponents, with and without technology (limited to whole numbers). 

Performance Indicators: 

N09.01 Demonstrate and explain, with examples, why there is a need to have a standardized order of operations. 

N09.02 Apply the order of operations to solve multi-step problems with or without technology (e.g., computer, calculator). 

PR03 Students will be expected to represent generalizations arising from number relationships using equations with letter variables. 

Performance Indicators: 

SCO PR03 Students will be expected to represent generalizations arising from number relationships using equations with letter variables. [C, CN, PS, R, V] 

PR03.01 Write and explain the formula for finding the perimeter of any regular polygon. 

PR03.02 Write and explain the formula for finding the area of any given rectangle. 

PR03.03 Develop and justify equations using letter variables that illustrate the commutative property of addition and multiplication (e.g., a + b = b + a or a × b = b × a). 

PR03.04 Describe the relationship in a given table using a mathematical expression. 

PR03.05 Represent a pattern rule using a simple mathematical expression, such as 4d or 2n + 1. 

ICT

  • P2: Students will be expected to use digital tools to develop ideas and original works in innovative ways.

  • TOC1: Students will be expected to

* safely use many forms of current technology for learning with growing competence

* demonstrate conceptual understanding of how information and communication technology, digital tools, and authorized networks support their learning

* use terminology related to information and communication technology

Grade 7

Mathematics

PR05 Students will be expected to evaluate an expression given the value of the variable(s). 

Performance Indicator: 

PR05.01 Substitute a value for an unknown in a given expression and evaluate the expression. 

Technology

  • GCO1: Students will be expected to design, develop, evaluate, and articulate technological solutions

  • GCO2: Students will be expected to operate and manage technological systems

Grade 8

Technology

  • GCO1: Students will be expected to design, develop, evaluate, and articulate technological solutions

  • GCO2: Students will be expected to operate and manage technological systems

Ontario - Grade 6-8 - Mathematics

Grade 6

Mathematics

Algebra

  • C3.1 solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves conditional statements and other control structures

Grade 7

Mathematics

Algebra

  • C3.1 solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves events influenced by a defined count and/or sub-program and other control structures

Grade 8

Mathematics

Algebra

  • C3.1 solve problems and create computational representations of mathematical situations by writing and executing code, including code that involves the analysis of data in order to inform and communicate decisions

Prince Edward Island - Grade 6-8 - Science

Grade 6-8

Science

  • GCO: Skills - Students will develop the skills required for scientific and technological inquiry, for solving problems, for communicating scientific ideas and results, for working collaboratively, and for making informed decisions.

Quebec - Grade 6-8 - Science

Grade 6-8

Science (Strategies)

  • Exploring various ways of solving the problem

  • Exchanging information

  • Comparing different possible explanations for or solutions to a problem in order to assess them (e.g. full-group discussion)

Saskatchewan - Grade 6-8 - Science

Grade 6-8

Science (Goals)

  • Develop Scientific and Technological Skills – Students will develop the skills required for scientific and technological inquiry, problem solving, and communicating; for working collaboratively; and for making informed decisions.