Users Manual

CLASS 4
78
TORI Piano activation coding
The infrared sensor connected to digital port 3 should be able to play both the role of recording and playback. You
can use a timer so that one infrared sensor can do two things. You can think of a timer as a stopwatch in progress
in the scratch program. Let’s code the program that start recording when the IR sensor of digital port 3 is pressed
more than 2 seconds, and plays the recorded sound when pressed less than 2 seconds.
Use the script we made previously to make a script like the one above. Reset the timer when the value of the digi-
tal 3 sensor is 'true.’ Up to this point, you're holding the digital 3 infrared sensor. The ‘repeat up to ~’ block is the
block that repeats the script until the certain condition is met. As you can see above, the condition for this block
in this case is “is sensor digital 3 is pressed? Is not.” In other words, the block continues to run internal scripts until
the user removes the infrared sensor. The ‘If~’ block inside has the condition of ‘time>2.’ If timer is greater than
2, the contents saved in ‘Beats’ and ‘note’ lists are deleted. This is the process of emptying the list for purpose of
recording. In conclusion, if the user presses the digital 3 infrared sensor for more than 2 seconds, the list of 'Beats'
and the 'note' list are all deleted.
TORI Piano coding activity