agsdix-fas fa-child

Light control panel

We will use functions to create a light game with two buttons.

info outline icon
Intermediate activity; Functions; Repeat while; Touch button; Lamp.

What are we going to do?

¿Eres Profesor?

Lesson Plan

Courses

  • Grades 6-12
  • 6th grade – 12th grade courses

Materials

  • Cell phone, tablet, or computer
  • Internet connection

Description

In this activity, students can experiment with Protobject, learning visual programming and computer science safely and playfully with a device.

Educational Objectives

  • Understand the concept of functions.
  • Create a technological object (prototype) using a device.
  • Identify relationships between technology and the surrounding world.
  • Evaluate personal and others’ work individually or in teams.
  • Discuss and reflect on ideas for improvement.

Beginning (10 minutes)

Welcome students to the class and briefly introduce the day’s activity: “Today we will learn how to prototype a light switch panel.”

We will start the class by providing students with technical knowledge for meaningful learning of the practical activity.

To begin the lesson, we can start with a question:

Do you know what functions are in programming?

Functions are groups of code that you can reuse whenever you need them in your algorithm.

We can categorize them as functions without parameters or with parameters. For example, if we have a recipe for cooking dinner with five steps, every time we want to cook dinner, we would have to write those five steps.

With functions without parameters, we can give those five steps a name and use them whenever we need them.

Functions with parameters, on the other hand, accept input data to perform the actions we have programmed. It’s like completing a sentence; you are given certain parts of a sentence but leave some parts blank, which will be filled in by the parameters.

Functions with parameters

Functions with parameters accept input data to perform the actions we have programmed. It’s like completing a sentence; you are given certain parts of a sentence but leave some parts blank, which will be filled in by the parameters.

To explain it better, we could create a light sequence and name it as a function, then tell it in which color we want that function to be executed. The color would be the parameter, and it would follow the same steps but change the color based on the parameter.

Finally, to start the prototyping process and make them feel like protagonists of their learning, ask them:

Shall we prototype a light switch panel?

Development (20-30 minutes)

We connect our devices to the Protobject platform. For this exercise, we will use the TOUCH BUTTON and the LAMP.

Remember to experiment on your own beforehand before asking students to experiment with Protobject so that you can anticipate questions that may arise.

You can follow the activity’s code step by step, and if you have any questions, read the commented code.

To test the prototype, we will instruct the students to click the activation button.

Congratulations!

Closure (5-10 minutes)

Now that you have programmed a noise sensor:

Try modifying values! How do we change the colors?

How do we change the speed of the light pattern?

And if we wanted to create more light patterns?

Challenge: Modify the project to display a message on the screen that says “Go” in green or “Stop” in red.

Hint: Add the component DibujarEscribir to write on the screen. Then, to write the message, define a new function with parameters for the text and color to handle writing the message on the screen.

Check out the challenge solution.

agsdix-fas fa-book-reader

Learn

What are functions?
Functions are groups of code that you can reuse whenever you need it in your algorithm.

They can be without parameters or with parameters.

For example, if we have a recipe to make dinner with five steps, every time we want to make dinner, we would have to write those five lines of code.

With functions without parameters, we can give a name to those five steps and use them whenever we need them. We can, for example, call it “DINNER,” and we would only have to call that function, and dinner would be ready.

They are called without parameters because there is no new information entering our function; DINNER will be executed in the same way every time we call it.

Functions with parameters

On the other hand, we have functions with parameters, which means that our function receives data to perform the actions we’ve programmed. You can imagine it as when you have to complete a sentence; they give you certain parts of a sentence but leave other parts blank. That blank space is filled by the parameter.

Following the previous example of DINNER, we can tell it to prepare the DINNER function, but the result will be different if the ingredients (parameter) we have are noodles or rice.

To better understand, we could create a light sequence and name it as a function, and then tell it in which color we want that function to execute. The color would be the parameter, and it would execute following the same steps but changing the color according to the parameter.

Prototipar

For this activity, we need 3 smartphones.

1

In the first one, we add the device Lamp

2

On the second smartphone, we add the first TouchButton

3

On the second smartphone, we add the second TouchButton. Remember that if you don’t have smartphones to add the touch buttons, you can click Open in this window to open them on the same computer.

plus square icon

Tip: In Protobject, you can add more components on the same smartphone by pressing the SCAN button as many times as you need.

We are ready to start prototyping!

Code composition

Click on question circle icon to open the comments that explain the code.
agsdi-bulb-options

Reflect

Now that you’ve already programmed a light panel:

Try modifying values! How do we change the colors?

How do we add other buttons with different colors? How do we change the speed of the light pattern? What if we wanted to create more light patterns?

plus square icon

Challenge: Modify the project to display a message on the screen that says “Go” in green or “Stop” in red.

Hint: Add the component WriteDraw to write on the screen. Then, to write the message, define a new function with parameters for the text and the color, which will handle writing the message on the screen.

We are ready to continue programming!