agsdix-fas fa-child

Alarm with switch

With this activity, you will learn how to create an alarm that can be activated with a switch.

info outline icon
Basic Activity; Events; States; Main Loop; Conditional.

What are we going to do?

Are you a teacher?

Lesson plan

Courses

  • Grades 3-12
  • Courses from 3rd grade to 12th grade

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 an event.
  • Create a technological object (prototype) using a device.
  • Identify relationships between technology and the surrounding world.
  • Evaluate personal and others’ work in individual or team efforts.
  • Engage in dialogue and reflection on improvement ideas.

Beginning (10 minutes)

Welcome students to the class and briefly introduce the activity of the day:

Today, we will learn how to create a simple alarm that plays a sound when you press a button.

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

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

Do you know how a button works?

In practice and in the world of computing, there is the well-known binary system. This is a numbering system where numbers are represented using only the digits 0 and 1, meaning only 2 digits.

Generally, the operation of these looks like this:

0: off, deactivated.

1: on, activated.

With this in mind, we will add a touch button that allows us to sound an alarm based on whether we activate or deactivate it. Additionally, we can choose the alarm sound ourselves.

 

Development (20-30 minutes)

Connect your device to the Protobject platform; this will enable us to use the button we want to create from the programming command screen and control the alarm.

To carry out the practical part of the activity, follow the steps in the “Prototyping” section. Remember to experiment yourself in advance before asking the students to experiment with Protobject. This way, you can anticipate questions that may arise in the students.

Conclusion (5-10 minutes)

Now that you’ve created a touch-button alarm, ask yourself:

How could we have more than one button?
What other prototype can you think of creating with this new information?
Where else could we find events?

We are ready to continue programming!

To solve the challenge presented, simply create a variable that increments each time the switch is activated.

Check the solution to this challenge.

agsdix-fas fa-book-reader

Learn

How does a switch work?

We are going to create an alarm that will be activated by a switch, but… How does a switch work?

In practice, a switch has two states:

  • On: The switch is activated, represented by a 1.
  • Off: The switch is deactivated, represented by a 0.

Using this information, the computer can determine what to do based on the state of the switch.

A switch cannot have more than one state at a time!

And does the computer know about states?

The computer is constantly “monitoring” the switch, waiting for it to send a signal.

Every time the button changes state, it notifies the computer!

Once the computer receives the signal, it decides which action to take.

This is called an event!

And why not a main loop?

In a Main Loop, what the computer does is constantly repeat an instruction. If you don’t remember what a main loop is, you can go to this activity.

In this case, it’s as if the computer is constantly asking the switch: “Have you activated yet?! Have you activated yet?! Have you activated yet?!”

We could say that in a Main Loop, the computer keeps asking for the switch’s state even when it hasn’t changed its state!

In contrast, for events, the computer is waiting for the signal, so it’s the switch that notifies the computer that its state has changed.

We read the event… And then?

Once the switch sends the signal, the computer can decide what to do based on the switch’s state. Here, we can use conditionals!

In this case, if the switch is on, we can play a sound, and if it’s off, we stop it. This is an alarm!

Let’s get to work!

Continuing with the previously developed code, we will use a switch to switch between the on and off states. When the switch is in the on state, we will instruct the computer to play a sound. Conversely, if the switch is in the off state, we will instruct the computer to remain silent.

Make

Let’s create a prototype that allows sounding an alarm upon the activation of a switch.

The first step is to add two devices that enable us to (1) sound an alarm and (2) press a switch.

1

Press Add device  and select  AudioPlayer

2

Press DevicesAdd Device and select Switch

3

Remember that if you don’t have smartphones to scan the QR codes, you can press QR or click Open in this window to open the components 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 needed.

We are ready to start prototyping!

Code composition

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

Reflect

Now that you’ve created an alarm with a switch, ask yourself:


In what other cases could we encounter events?

plus square icon

Challenge: Let’s create an alarm that records (in a variable) and displays (using the DrawWrite device) how many times it has been activated!

In the next activity, we will explore in more detail the difference between events and the main loop.