count.jpg




The goal of this app is create an app that counts out loud. This video shows its functioning.


First, create a new project.


Design: You will need a button that directs the device to start counting

Design: You will need a TextToSpeech element to speak the value.

Design: You will need a Clock. The clock will enable you to do so something at every interval of time.


After the design phase, your screen might look like:


CountingScreen.PNG

Blocks:

1. When the start button is clicked, set the Clocks.TimerEnabled to True.


2. You will need a variable to store an integer (a whole number).

A) We will call this variable "Count."


3. When the timer fires (this is found in clock called when.Timer), you will want to have the TextToSpeech element speak the value in the variable. This video shows you how to create and modify the variable.


4. If we don't change the variable, our TextToSpeech element will just keep saying the same number in the variable over and over again. We need a way to increase the variable each time the timer fires.

A) We will increment (or add 1) our Count variable each time the Timer fires. We add one to the old value of our Count and store in back in the Count.

Inc.PNG

B) Note the block above sets our variable Count to the old value of of count + 1. So if our old value was 0, then when the timer fires it will add 0 + 1 for a new value of 1. The next time it fires it will add 1 to 1, so it will be 2.

5. We also need to stop the counting by setting the Clock.TimerEnabled to false when the value is too high. Let's count to 30 and stop. Stopping is done using an if-then statement. In English, we would say, "If Count is bigger than 30, then set Clock.TimerEnabled to false". In programming, it is pretty much the same thing:

Count.if.then.PNG

This video clip shows how to grab the pieces.


6. Test your App!



Challenges
1. (*) Allow the user to change the increment (so they can count by 5's for example)
2. () Use modulo arithmetic to decrease the timerInterval every five counts. The test for a multiple of five looks like
Modulo.PNG

3. (*) Randomly change languages every five counts.
4. () Have the program speak the numbers between 1 and 100. But for multiples of three, speak "Hello" instead of the number. For multiples of five, speak "There". For numbers which are multiples of both three and five, speak "Yes".


Useful Terminology
Incrementing -- Increment operators are used to increase the value of the variable. This allows us to change a variable with some regularity.
If-then Statement** -- IF-then statements are conditional statements that state that when X occurs, then Y occurs.