Challenge 2.4: Choose your own patter
Choose your own patter
Goals
In this assignment you will practice the following computer science concepts in a team or small group environment:
- Calling Actions on Objects
- Using the Quorum Lego Library to move the robot, play sounds and turn on the L.E.D.
- Practice solving technical problems together in a group.
Computer Science Principles Curriculum
- Big Idea: Creativity: EU 1.1, LO 1.1.1, EK 1.1.1B, EU 1.2, LO 1.2.1, EK 1.2.1E, EK 1.2.4 A,C,D
- Big Idea: Algorithms: EU 4.1, LO 4.1.1, EK 4.1.1H
- Big Idea: Programming: EU 5.1, LO 5.1.2, EK 5.1.2I
Common Core Standards
- English Language Arts Standards » Science & Technical Subjects: CCSS.ELA-Literacy.RST.9-10.3, CCSS.ELA-Literacy.RST.9-10.4, CCSS.ELA-Literacy.RST.9-10.5, CCSS.ELA-Literacy.RST.9-10.7, CCSS.ELA-Literacy.RST.9-10.10, CCSS.ELA-Literacy.RST.11-12.3, CCSS.ELA-Literacy.RST.11-12.4, CCSS.ELA-Literacy.RST.11-12.5, CCSS.ELA-Literacy.RST.11-12.10
- Standards For Mathmatical Practice: CCSS.Math.Practice.MP1, CCSS.Math.Practice.MP2, CCSS.Math.Practice.MP4, CCSS.Math.Practice.MP5, CCSS.Math.Practice.MP6, CCSS.Math.Practice.MP7, CCSS.Math.Practice.MP8
Overview
In this challenge students will move their robot through an obstacle course of thier own creation while meeting certain minimum requirements.
Goal 1: Learn how to play a .WAV file on the robot
In order to play a .WAV file on your computer, follow these instructions:
- Instantiate a sound object as you've learned in previous lessons.
- Upload a .WAV file to the SD card on the robot.
- Use the PlayAudio action to play a wave file
Use this code template for your file, changing the path name to the location of the .WAV file on your PC. In this example, our WAV file is located in a directory called "assets" in our main project folder.
use Libraries.Robots.Lego.Sound
use Libraries.System.File
Sound soundCtrl
File soundFile
soundFile:SetPath("assets/")
soundCtrl:PlayAudio(soundFile)
In your pattern, you must use at least one RotateToDegree
statement and one RotateByDegrees
statement. You can combine them as you want to what better fits your pattern.
Example: One way to combine both statements
motor:SetSpeed("B", 600)
motor:SetSpeed("C", 600)
motor:RotateToDegree("B", -1080)
motor:RotateToDegree("C", -1080)
motor:Wait("B")
motor:RotateToDegree("B", -3700)
motor:Wait("B")
Activity: Combine both statements to do your pattern
Read the checklist and use both statements the way you prefer to complete all the movements parts of it.
Goal 2: Using the Quorum Lego Library to wait the button to be pressed to perform a task
To wait for the button to be pressed you will need to use the Button
library that is also inside the Lego
library and you also need to instantiate a new Button
object called button
. You will use the WaitForButtonPress
statement to wait for button to be pressed. The WaitForButtonPress
doesn't take any parameters.
Example: Use the WaitForButtonPress
.
// This line waits the button to be pressed
button:WaitforButtonPress()
Use this example to wait for the button to be pressed to run the code given early in this challenge.
Activity: Use the WaitForButtonPress
statement.
Indicate when the program is waiting for the button to be pressed by using the LED and the tones.
To do it you will use the Button
library and the Sound
library that are inside the Lego
library and instantiate a new Sound
object called sound
. The command to turn on the LED is the SetLightPattern
that takes one parameter, the number of the pattern.
Example: Turn on the LED
// This line turns the LED on
button:SetLightPattern(1)
This example is turning the LED on in the pattern 1, that is the LED green and solid.
Activity: Turn the LED on, and make it blink
In this activity you will have to choose one pattern to your LED. You can choose the color but it must blink while waiting, so it must be the patterns 4(green), 5(red) or 6(orange).
The command to play tones is the PlayTone
that takes two parameters, the frequency and the duration of the tone.
Example: Play a tone
// This line plays a tone
sound:PlayTone(710, 100)
This example is playing a tone in the frequency of 710 Hertz with duration of 100 milliseconds.
Activity: Add tones
In this activity you will have to choose one tone to play while waiting for the button. Now you should insert these lines of code right before the lines with the command to wait for the button. And because you want the LED to be on just while waiting, right after the wait for the button command you should add a line to leave the LED without any color. The pattern that represents that is the pattern number 0.
Example: Turn off the LED
// This turns off the LED
button:SetLightPattern(0)
Sample Output
Each student will have a different pattern but all of them must include:
- At least one RotateByDegrees and one RotateToDegree
- At least one movement backward
- At least one clockwise revolution
- At least one counterclockwise revolution
- It has to wait until the button is pressed to begin and between each move
- And it must have the LED and the tone to indicate while it’s waiting
Next Tutorial
In the next tutorial, we will discuss Variables and Types, which describes how work variables and types in Quorum..