agsdix-fas fa-child

Stopwatch

With this activity, you will learn to create a stopwatch.

info outline icon
Basic Activity; Main Loop; Variable; Timing.

What are we going to do?

Are you a teacher?

Lesson Plan

Courses

  • Grades 3-12
  • Courses 3rd grade – 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 a variable.
  • Create a technological object (prototype) using a device.
  • Identify relationships between technology and the environment.
  • Evaluate one’s own work and that of others, both individually and in teams.
  • Engage in discussions and reflections to propose improvements.

Beginning (10 minutes)

Welcome the students to the class and briefly introduce the day’s activity:

Today we will learn to create a stopwatch that counts seconds.

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

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

Do you know how a stopwatch works?

The stopwatch’s job is to count the seconds that are passing. Each time a second goes by, the stopwatch says, “Oh, one second has passed, I will add 1 to the number of seconds I’ve already seen.”

So far, the computer hasn’t needed to store additional information to function. But now we need the computer to **remember** the count. To do this, we’ll use **variables**, which are like little boxes where data is stored. These data can be overwritten and edited, but you can’t store more than one piece of data in a variable. They can store any type of data, both numbers and text, but for this activity, we will only use numbers.

Development (20-30 minutes)

Connect your device to the Protobject platform. This will allow us to use the display we want to create with programming commands that will show the stopwatch.

To perform the practical part of the activity, follow the steps in the “Prototype” section. Remember to experiment on your own before asking students to experiment with Protobject. This way, you can anticipate questions that may arise from the students.

Closure (5-10 minutes)

Now that you’ve created a stopwatch, ask yourself:

What other values could we store in a variable?
What other prototypes can you think of with this new information?
How can we store the minutes of the stopwatch?

We are ready to continue programming!

To solve the challenge, it’s necessary to create another variable to store the minutes. The process is analogous, except that you’ll need to add another loop inside the main loop. This loop repeats the process of increasing the seconds 60 times, and once the repetition is complete, 1 is added to the minutes variable, and the seconds are reset.

See the solution to this challenge.

agsdix-fas fa-book-reader

Learn

How does a stopwatch work?

The stopwatch simply counts the seconds that are passing. Every time a second passes, the stopwatch says, “Oh, one second has passed, I will add 1 to the number of seconds I’ve already seen.”

This way, if the stopwatch has counted 9 seconds, when another second has passed, it will add 1 to that number, which is 9 + 1 = 10 seconds. Then the process repeats… This is a loop!

What if we lose count?

Have you ever forgotten what number you were at and had to start counting all over again? The computer can experience that too!

One possible solution to this problem is to note down somewhere the number we are at. Then, when we want to continue counting, we simply add 1 and write it down again so we don’t forget. It’s a value that constantly changes!

How does the computer “note” things?

Do you remember the concept of a Variable that we discussed in some previous activities? In this activity, we will use it in a slightly more advanced way.

Imagine a little box where you can store something, absolutely anything you like.

However, to avoid getting confused and to remember what you have stored in there, you decide to give a name to this box.

This is a variable!

Using variables, we can make the computer keep counting without forgetting what number it’s at.

And how do we use it?

time = 0

To use a variable, it’s necessary to give it a name so we don’t forget what we’ve stored in it. In this case, we can call it “time.”

Next, we need to give it an initial value. Since we want to count, the starting value is 0, so at the beginning of the program, the variable “time” is equal to 0.

Variables… They change!

As the name suggests, the value of a variable can change. Consequently, we can modify its value and save it again in the same variable.

In the case of the variable “time“, in each iteration of the main loop, we add 1 to its value. And we are already counting!

Let’s get to work!

To prototype with variables, we will start by giving a name to the variable, a process known as “naming” it (for example, “time”). Then, we will assign it an initial value, which in this case will be 0. Next, we will create a loop that will increase the value of our “time” variable by 1 each time a second passes.

Make

Let’s create our stopwatch.

1

Press Add device and select the WriteDraw component called Stopwatch so we can write the numbers.

2

Scan the QR code

3

Remember that if you don’t have a smartphone to scan the QR codes, you can press Open in this window to open the components on the same computer.

We are ready to start prototyping!

Code composition

Click on the question circle icon to open the comments explaining the code.

Variables are managed through the  Variables category

agsdi-bulb-options

Reflect

Now that you’ve created a stopwatch, ask yourself:

How could we store the minutes of the stopwatch?

plus square icon

Challenge: Let’s create a stopwatch that includes minutes!

 

Hint: We could create a loop within the main loop, which runs 60 times, incrementing the seconds by 1 in each iteration. Meanwhile, the main loop also increments another variable that keeps track of the minutes.

In the next activity, we’ll start working with conditionals!