Lighthouse With Gentle Flashing and Switch

by Protobject in Teachers > 6

43 Views, 0 Favorites, 0 Comments

Lighthouse With Gentle Flashing and Switch

main.jpg

In this project, we will build a lighthouse where the light flashes gradually and can be turned on and off using a switch. This activity is perfect for programming learners and involves concepts such as loops, timing, and conditionals.

Supplies

  1. 2 Smartphones (one to simulate the lighthouse light and the other to act as the switch)
  2. Cardboard (to build the lighthouse and the scene)
  3. Colored Printer (to print the lighthouse and scene)
  4. Paper (to create origami boats)
  5. Internet Access (to use the Protobject platform online)

Build the Lighthouse Scene

support.jpg
smartphone-holder.jpg
placeholder.png
  1. Use the cardboard to construct the lighthouse and the surrounding scene (see support picture).
  2. Print the lighthouse scenario (see PDF files and the attached grid to understand how to build it).
  3. Create origami boats using paper and place them around the lighthouse.

Access the Platform

0.add-device.png

Visit the Protobject platform at https://app.protobject.com using Chrome or any Chromium-based browser (e.g., Edge, Opera).

Add Devices

1.lamp.png
2.switch.png
  1. On the first smartphone, add the Lamp component.
  2. On the second smartphone, add the Switch component.

Learn About the "For" Loop

A “count with variable” loop, called “for” in programming, is a control structure 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

Understand the Switch Functionality

The switch controls whether the lighthouse light is on or off. When the switch is enabled, the light will gradually increase in intensity from 0 to 100 and then decrease back to 0. If the switch is disabled, the light will turn off immediately. This is achieved through a conditional block.

Program the Lighthouse Light

code.png

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.

The conditional is used to run or stop the aforementioned process.

The code is already prepared for you!

You can view it in detail at this link. Comments are included to provide clarification when needed.

You can also open the project directly in Protobject to avoid manually setting it up.

Test Your Lighthouse

Lighthouse
  1. Turn on the switch on the second smartphone to start the light flashing.
  2. Observe the light gradually increasing and decreasing in intensity.
  3. If the switch is turned off, the lamp will turn off.

Challenge Yourself

  1. Add Sound Alerts: Integrate the MusicalKeyboard component to play a sound when the light reaches its maximum or minimum intensity.
  2. Adjust to Your Preference: Fine-tune the calibration to achieve varied light flashing timings.

Enjoy Your Lighthouse With Gentle Flashing!

By only using your smartphones, you’ve created a practical and fun lighthouse with gentle flashing lights without needing extra hardware.

Happy building and coding!