agsdix-fas fa-child

Lighthouse with gentle flashing and switch

Build a lighthouse where the light flashes gradually and can be turned on and off using a switch

info outline icon
Intermediate Activity; For, Timing; Variables; LED.

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 with a device in a safe and playful manner.

Educational Objectives

  • Understand the concept of FOR loop
  • Create a technological object (prototype) using a device
  • Identify relationships between technology and the surrounding world
  • Evaluate their own and others’ work in individual or team projects
  • Discuss and reflect on ideas for improvement

Beginning (10 minutes)

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

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

To kick off the class, we can begin with a question:

Have you ever heard of the FOR loop?

You can give the students the floor to propose their answers and then supplement with the correct answer.

A “count with variable” loop, called “for” in English, is a control structure in programming used to repeat a block of code a specific number of times. One of the key components of a “count with variable” loop is the iteration variable, used to keep track of the loop’s progress.

Components of the “count with variable” loop:

1. “Variable” block: represents the iteration variable used in the loop. It can be a counter or any other variable needed to control the loop.

2. “Initial value” block: defines the initial value of the iteration variable.

3. “Final value” block: indicates the final value used to evaluate the loop termination condition.

4. “Steps” block: specifies how the iteration variable will be updated in each iteration of the loop. It can be an increment or decrement.

For example, if we want to count up to 10, it would look like this:

“Variable” block: counter.

“Initial value” block: 0

“Final value” block: 10

“Steps” block: 1

“Final value” block: 10

“Steps” block: 1

How do we use it?

“Count with variable” is different from a loop where we don’t know how many times the task should repeat as it repeats indefinitely. It is also different from “repeat N times” as it iterates over the variable we have created.

To understand it better, we will build an example using the concept of “count with variable.”

To gradually turn on the light of a lighthouse, we will use a range of values from 0 to 100, increasing the value by 1 each time. We will assign this value to the red, green, and blue components of the lamp. To gradually turn off the light, we will use a range of values from 100 to 0, decreasing the value by 1 in each iteration. We will assign this value to the lamp in the same way as when turning on the light.

Do you want to learn how to prototype a lighthouse?

We connect our equipment to the Protobject platform. For this exercise, we will use a LAMP and a SWITCH

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

You can follow the step-by-step code of the activity, and if you have questions, read the commented code.

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

Congratulations!

Reflect (10 minutes)

Do you remember the “repeat while” block we saw in the previous activity?

What is the difference between “count with variable” and “repeat while”?

Are there cases where you can use only the “repeat while” block and not the “count with variable” block?

Challenge: Modify the project to function the same way using “repeat while” instead of “count with variable.”

Hint: Modify the “intensity” variable with the “add value to variable” block.

See the challenge solution.

agsdix-fas fa-book-reader

Learn

Do you know what FOR is in programming?
A “count with variable” loop, called “for” in English, is a control structure in programming used to repeat a block of code a specific number of times.

One of the key components of a “count with variable” loop is the iteration variable, which is a variable used to keep track of the progress of the loop.

Components of “count with variable

  1. Variable” block: represents the iteration variable used in the loop. It can be a counter or any other variable you need to control the loop.
  2. Initial value” block: defines the initial value of the iteration variable.
  3. Final value” block: indicates the final value that will be used to evaluate the loop termination condition.
  4. Steps” block: specifies how the iteration variable will be updated in each iteration of the loop. It can be an increment or decrement.

For example, if we want to count up to 10, it would look like this:

  1. Variable” block: counter.
  2. Initial value” block: 0
  3. Final value” block: 10
  4. Steps” block: 1

How do we use it?

Count with variable” is different from a loop where we don’t know how many times the task should repeat as it repeats indefinitely.

It is also different from “repeat N times” as it iterates over the variable we have created.

To better understand it, we will build an example using the concept of “count with variable.”

To gradually increase the light of a lighthouse, we will use a range of values from 0 to 100, increasing the value by 1 each time. We will assign this value to the red, green, and blue components of the lamp.

To gradually decrease the light, we will use a range of values from 100 to 0, decreasing the value by 1 in each iteration. We will assign this value to the lamp in the same way as when turning on the light.

Make

We are going to create a prototype that allows controlling the lighthouse.

We need 2 devices: 1 lamp and 1 switch.

1

Press Add Device, select Lamp, and press Open in this Window to open the lamp on the same computer or use a smartphone.

2

Press DevicesAdd Device and select Switch

We are ready to start prototyping!

Code composition

Do you remember the “repeat while” block we saw in the previous activity?

What is the difference with “count with variable“?

Are there cases where you can use only the “repeat while” block and not “count with variable“?

agsdi-bulb-options

Reflexionar

¿Recuerdas el bloque “repetir mientras” que vimos en la actividad anterior?

¿Que diferencia hay con el “contar con variable”?

¿Hay casos donde se puede usar solo el bloque “repetir mientras” y no “contar con variable”?

 

plus square icon

Challenge: Modify the project to make it work the same way using the “repeat while” block instead of the “count with variable.”

Hint: Modify the “intensity” variable with the “add value to variable” block.

In the next activity we will learn about functions!