10 Minutes of Code:
TI-Nspire™ CX Technology &
Short, easy-to-teach activities design to be completed in order, using TI-Nspire™ CX and TI-Innovator™ technology.
Unit 1: Getting Started with TI-Innovator™ Hub
Skill Builder 1 Your First ProgramTeacher's Notes
In this first lesson for Unit 1, you will learn about working in the Program Editor to write a program that controls a light on the TI-Innovator™ Hub.
- Use the TI-Nspire™ CX Program Editor
- Use the Send command to control a light on the TI-Innovator™ Hub
- Introduction to the Wait statement
- Timing on the TI-Innovator™ Hub and the handheld
Connect the TI-Innovator™ Hub to the TI-Nspire™ CX. The handheld will turn on. On the TI-Innovator™ Hub, a green light illuminates, indicating that the TI-Innovator™ Hub has power and is ready.
When learning to program a handheld with the TI-Innovator™ Hub, you will be learning to program in two separate but connected worlds: the handheld and the TI-Innovator™ Hub.
When writing a program on the handheld, use the Program Editor found on the menus when starting a document, adding a page, or in the Calculator app menu.
- The Send command is used to send commands the TI-Innovator™ Hub that produce a physical reaction (lighting up a light, making a sound, turning on a motor, etc.).
- The TI-Innovator™ Hub commands are found on the Program Editor’s menu under the HUB submenu.
Setting up the LIGHT Program:
Your first program will tell the TI-Innovator Hub to turn on the red LIGHT (LED) for 5 seconds.
- To begin writing a new program, open a new document or insert a page in the current document (ctrl+doc), and select Add Program Editor. Select New.
- Type a name for the program (we use the name light1 here), and press enter.
The cursor is now in the dotted box between Prgm and EndPrgm.
The parentheses after the program name are used for adding optional parameters.
Your program consists of only one line of code:
Send(“SET LIGHT ON TIME 5”)
LIGHT is the name of the red LED.
To create this statement, you must:
- Press the menu key, and select the HUB menu.
- Select the Send “SET… menu item.
- Then select the LIGHT from the Send "SET submenu.
The Hub submenu contains statements related to programming the TI-Innovator™ Hub and the TI-Innovator™ Rover. These statements can be typed in by hand, but it is usually easier to select them from the menu.
- Finish the statement by completing the rest of the command. ON and TIME are located in the menu > Hub > Settings submenu.
Send “SET LIGHT ON TIME 5”
The complete program is shown to the right.
The Send command will send the string (the text in quotes) to the TI-Innovator™ Hub.
Running the Program:
- Press ctrl+R to run the program. This performs ‘Check Syntax & Store’, adds a Calculator app on the following page, and inserts the program name onto the edit line of the Calculator app.
- Make sure your TI-Innovator Hub is connected to the handheld.
- Press enter to run the program.
If the command is written correctly, the LIGHT (the red LED) will light up for 5 seconds. If there’s an error in the TI-Innovator Hub instruction, the red light flashes once and a beep will sound.
The handheld displays ‘Done’ when the program ends. Notice that the program actually ends before the light goes off. To make the program end when the light goes off, we have to tell the handheld to Wait as long as the light is on.
To add a statement to the program, we need to edit it:
- Switch to the Program Editor on the previous page
- Add a blank line to the program by placing the cursor at the end of the Send statement and pressing enter.
- Wait is located in the Hub submenu.
- Add the statement Wait 5 before EndPrgm.
Run the program again (ctrl+R).
The Calculator app on the next page reappears, and the program name is pasted again. Press enter. The program will end at roughly the same time the red light goes off.
We can remove the TIME element of the Send instruction and control the timing using the Wait command in the handheld. Since the LED will stay on once it is turned on, you will also have to turn the light OFF in your program.
- To turn the light off, use the statement:
Send “SET LIGHT OFF”
- Add statements to the program to make the light blink many times.
Skill Builder 2 Input and ColorTeacher's Notes
In this second lesson for Unit 1, you will learn about input to a program and controlling the COLOR LED on the TI-Innovator™ Hub.
- Use arguments to a program
- Control the COLOR LED
The COLOR LED (light emitting diode) has three color ‘channels’: red, green, and blue. This is often referred to as a, “RGB LED”. Computer screens, phone screens and TV screens all use a large number of these LEDs to create images.
To get a particular color, you have to mix the right amounts of the three colors red, green, and blue. Many other colors are possible with the right mix of these three primary colors.
First let’s control the COLOR LED right from the Calculator app:
- Add a Calculator app page.
- Press menu > Functions & Programs > I/O, select the Send command.
Note that many of the programming commands are available and can be used in the Calculator app. You can test TI-Innovator™ Hub commands without writing a program.
- After the keyword Send, type both leading and trailing quotation marks with one step by pressing ctrl-[X].
- Inside the quotation marks, type
SET COLOR (Note: It is case sensitive.)
- Enter three numeric values separated by spaces. These numbers represent the amount of
red, green, and blue to light to be produced.
- Each of the three numbers must be between 0 and 255, inclusive. The higher the number, the brighter the color. See some examples to the right. The first number is the amount of RED, then GREEN, then BLUE light to produce.
Notice that the LED stays lit until it is changed. A program can help control the LED more precisely by turning it off before the program ends.
In the program, you will experiment with the COLOR LED. You will provide red, green, and blue values as arguments. The LED will light up in the color that you chose for a few seconds and then turn off the LED.
Setting up the COLOR Program:
- Add a new page by pressing ctrl+doc, or start a new document. Select Program Editor from the menu.
- Name the program color01.
- Inside the parentheses after the program name, type three letters separated by commas to represent the colors red, green, and blue.
- These are called ‘arguments’ to the program and will be used by the program to send the three color values to the TI-Innovator™ Hub.
- We used the letters r,g,b on the right.
Arguments are ‘placeholders’ for values that you will provide when you run the program. They are variables that the programs uses to represent your actual values. These variables exist only for the program and are not available to other apps and so are treated as ‘local variables’.
- Select menu > Hub > Send “SET… > COLOR to paste the first part of the command into the program.
Understanding eval( ):
You cannot send the variables r, g, and b as the color values in the Send statement because the letters r, g, and b would be sent to the TI-Innovator™ Hub rather than the values of the variables.
We need to use a special function, eval( ) from the Hub menu which is designed to convert the value of an expression in the handheld into a string representation that the TI-Innovator™ Hub can process.
Complete the Send Statement:
- Add the eval( ) function by selecting menu > Hub > eval(.
- Type the letter r in the parentheses.
- Add a space after the parentheses.
- Repeat the eval( ) function two more times for g and b. Don’t forget to add a space in between each. The Send statement should look like image to the right.
- After the Send statement, add a Wait statement to wait a few seconds. Remember to provide a number of seconds.
- Finally, add another Send “SET COLOR … statement to turn the color LED off.
- Use three 0’s to turn off all three colors.
Run the Program:
- Be sure that the TI-Innovator™ Hub is connected.
- Press ctrl+R to check, store, and run the program.
- In the Calculator app, inside the parenthesis, provide three numbers separated by commas representing the amount
of red, green, and blue light to mix. Then, press enter.
- The color LED lights up for the number of seconds you specified in the Wait statement and then turns off.
Note: To run the program again with different values, press the up arrow twice to highlight the program name, press enter, and edit the numbers before pressing enter again.
Skill Builder 3 Request and SOUNDTeacher's Notes
In this third lesson for Unit 1, you will learn another method to get user input into a program and how to control the SOUND on the TI-Innovator™ Hub.
- Use the Request statement
- Control the frequency and timing of the speaker (SOUND)
The TI-Innovator™ Hub has a built-in speaker called SOUND.
You control the sound coming out of SOUND by sending it a frequency value. Sound frequencies are measured in Hertz (Hz), or ‘cycles per second’.
The Request statement is found in the I/O menu. It is used to get input from the user and contains a feature that lets the programmer create a meaningful message to the user.
Statement Syntax: Request <string> <variable>
In this sound program, we’ll use the Request statement.
Setting up the SOUND Program:
- Start a new program, and call it SOUND1.
- Add the Request statement from the I/O menu.
- After the keyword Request, add the prompt “Frequency? ” and a comma.
- Then type the variable that will represent the frequency, freq, and press enter.
- Add another Request statement to let the user enter the time for which the sound should play.
As with the COLOR program in the previous skill builder, you need to use the eval( ) function to evaluate the variables freq and time.
Finishing up the SOUND Program:
- Select Send “SET… and SOUND by pressing menu > Hub > Send “SET… > SOUND.
- Select eval( by pressing menu > HUB > eval().
- Add the variable freq inside the parentheses.
- Type a space, and then add another eval() function for the variable time.
- Press ctrl-R to store and run the program.
Run the Program:
When you run this program, two dialog boxes appear as a result of the Request statements.
- Enter the frequency 440 and time 5.
- This will play the tone 440Hz for 5 seconds. This means that the speaker vibrates 440 times a second for 5 seconds.
- In a noisy environment, you might have to hold the TI-Innovator™ Hub close to your ear to hear the tone.
- Press enter to rerun the program with another frequency and time.
- Experiment with other frequencies.
Application Traffic LightTeacher's Notes
Write a program that controls a traffic light.
- Control the COLOR LED to simulate a traffic light using a single bulb
- Create a sequence of statements with proper timing controls
Your task is to write a program that controls a traffic light. The light will be simulated using the COLOR LED on the TI-Innovator™ Hub.
The COLOR LED should switch from green to yellow to red AND from red to green. Timing is up to you.
Your program will have a sequence of statements that simulate the change from RED to GREEN to YELLOW to RED. A sequence control structure in programming is a set of statements that are processed one after another, from top to bottom, without interruption.
Using Text as a Pause:
The Disp command displays a message on the HOME screen of the handheld. It can be used to display the value of a variable as in Disp X, or it can display a string. But it does not stop the program from continuing.
The Text statement on the I/O menu displays a dialog box and waits for the user to press enter or click the ‘OK’ button before processing the rest of the program. The effect of Text is shown to the right.
Setting up the Title Screen:
- Begin a new program, and call it trafficlight.
- Select the Text keyword from the I/O menu.
- In quotation marks, add the message “Traffic Light:
Press enter…” as shown.
Set the Colors:
First, we set the color to red by sending the RGB values of 255 0 0.
In the example on the right, we use a Wait statement to tell the handheld to wait 5 seconds before sending the next command to the TI-Innovator™ Hub. The red light will stay on during this time.
Your task is to add the statements to make the light green, then yellow, then red again.
Challenge: Add SOUNDs to indicate the color of the light.
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3
Unit 2: For Loops with TI-Innovator™ Hub
Skill Builder 1 Blink the LIGHTTeacher's Notes
In this first lesson for Unit 2, you will learn about the For loop in the handheld through a program that makes the LED light blink while displaying information on the handheld screen.
- Learn about the For loop
- Make the light blink
- Use the DispAt statement for text and variables
Let’s write a program to make the LED light blink a certain number of times. With other input statements (or arguments) you can also control the amount of time that the light is on and off.
This program introduces you to the For…EndFor loop.
Setting up the Program:
- Start a new program, and call it light2.
- Add Text by selecting menu > I/O and selecting Text.
- Within quotation marks, add the text “Blink! Press enter” as shown.
- Add Request by selecting menu > I/O > Request.
- Within quotation marks, add the text “Number of times?” as shown.
- Add a comma and the variable n.
Adding the For Loop:
- Add the For structure by selecting menu > Control > For…EndFor.
- Both the For , , statement and the EndFor statements are pasted into your program with a line between them to add the loop body.
- Add the rest of the For statement’s pieces, i,1,n, between the commas provided.
- This statement means “For i going from 1 to n by ones.”
- Press enter a few times in the loop body to create blank lines that we’ll fill in next.
- Don’t worry about how many blank lines to enter. You can always add more lines if you need them, and blank lines have no effect when you run the program.
- The block of statements between For and EndFor is called the ‘loop body’. It is this section of code that will be processed n times thanks to the work done by the For loop.
We want the light to blink ON and OFF n times. We also want the handheld to display the number of the blink.
We’ll start the loop body with DispAt 1, i which is the loop control variable.
DispAt displays the expression following the comma at the line number in front of the comma. The output area of the program is below the program name and there are 8 lines available for DispAt to use.
Now add statements to turn the light ON and OFF as shown.
- Add Send “SET LIGHT from the Hub menu.
- Add the word ON from the Hub > Settings menu (or just type it).
- Add Wait (in seconds) from the Hub menu so that the handheld waits before sending the next command.
- In our program, we use 1 second, but you can use any values you like, including decimals.
- Add another Send statement to turn the light OFF, and then add another Wait statement.
- Store the program (ctrl+R). You should see the light blink and the counter increase on the Calculator app.
Notice the indenting? This helps to make programs more readable and has no effect on the running of the program.
Here’s a challenge: Add Request statements at the top of the program (before the For statement) to set the timings for each of the two Wait values (the ON time and the OFF time). Use those variables instead of numbers in the Wait statements.
Run the program again. Observe the blinking and the values displayed on the handheld screen.
Skill Builder 2 Loop through COLORsTeacher's Notes
In this second lesson for Unit 2, you will learn about controlling the intensity of the three colors of the COLOR LED on the TI-Innovator™ Hub.
- Use For loops to control each of the three color channels on the COLOR LED
The red, green, and blue values (from 0 to 255) sent to the COLOR LED determine the brightness of each color channel. This program demonstrates varying the amount of each color gradually to transition through some of the over 16 million (256³) colors possible. You will again use some For loops in your program.
Creating a Color Changer Program:
- Start a new program, and call it color2.
- Add Text with the title of the program as shown.
- Add Request and, in quotations marks, add the text Wait time?.
- Then add a comma and the variable w.
- This variable will be used in a Wait statement. The lower the number, the lower the wait time, and the faster the program executes the next command.
- As shown on the right, also Request a Step value to be used in the For loop to control the speed of the color change.
Notes: Local i, w, s prevents the variable from being created in the problem (outside the program). The comment symbol © is available from menu > Actions > Insert Comment.
Our program will gradually (depending on the wait and step values) increase the RED intensity, then add GREEN, then gradually take away the RED, then add BLUE, take away GREEN, then add RED to the BLUE, then take away the BLUE, then finally take away the RED. This is a rather long program, and you can run it after you complete each of the For loops to test the code.
The editor automatically provides both the For statement and its corresponding EndFor statement at the same time so that you don’t forget it later on.
- Add a For…EndFor loop (from the Control menu) after the two Request statements using the step variable s as the fourth parameter in the For statement.
Complete the First Loop:
- Add the rest of the components of the For statement to make the value of i go from 0 to 255. Use the loop variable i and the step variable s.
- Add the Send “SET COLOR statement from the Hub menu.
- Use the eval( ) function from the Hub menu for the variable i to control the red channel and set the GREEN and BLUE channels to 0.
- Follow the Send statement with the Wait statement using the variable w that you used in the Request statement earlier.
- After the End of this first For loop, you can use the Text statement with a message in order to admire that bright red LED.
Add the Green Light Loop:
Now we’ll build another For loop to add GREEN to the LED. But this time we want to only control the GREEN channel and not touch the RED channel. We can do this in two ways:
Send “SET COLOR 255 eval(i) 0”
(since we know that the RED is all the way on and the BLUE is off)
Send “SET COLOR.GREEN eval(i)”
This second statement controls only the GREEN channel and does not affect the RED and BLUE channels. In both cases, notice that we can reuse the variable i from the first For loop.
In the image to the right, note that we chose to use the first method.
- Add the Wait statement inside the loop body using the variable w.
- Add the Text statement after the End of the loop again to admire the new color. What color is that?
Now we want to gradually decrease the amount of RED so that we are left with only GREEN.
To decrease in a For loop, we start with the highest number, go to the lowest number, and use a negative step value:
For i, 255, 0, -S
starts at 255 and subtracts S in each step of the loop until the variable i is less than 0 when the loop ends. Be sure to use the [(-)] ‘negative’ key and not the subtraction key. That would cause an error.
We only want to change the RED channel so we’ll use COLOR.RED in the Send statement.
The rest of this loop is similar to the first two loops we constructed. The image to the right shows only the keywords entered.
Can you complete each of these statements? If not, refer to the next step.
The image to the right shows the completed section that removes the RED gradually. At the end of this loop, you should see a bright GREEN color:
- Now add a loop to add BLUE.
- Then add a loop to remove GREEN.
- Next add a loop to add RED again.
- What color do you see at the end of these loops?
- Then add a loop to remove BLUE.
- Finally, add a loop to remove RED.
- What color is the LED at the end of the program?
- What happens when all three color channels are 0?
Skill Builder 3 Loop through the musical notesTeacher's Notes
In this third lesson for Unit 2, you will learn about the relationship between the frequencies of the musical scale and write a program to play those notes that musicians have used for many centuries.
- Explain the ‘twelfth root of two’ relationship of the musical scale
- Write a program that plays successive notes in a scale
A Little Music Theory
Musical notes are determined by the frequency of a vibrating object such as a speaker, drum head, or string as in a guitar or piano. The notes of the musical scale have a special mathematical relationship. There are 12 steps in an octave. If a note has frequency F, then the very next note has frequency × 12√2.
Multiplying a note’s frequency by 12√2 or 21/12 (the twelfth root of 2) twelve times results in a doubling of the original frequency, so the last note in the octave (or the first note in the next octave) has frequency of F ×(21/12)12 = 2 × F. For example, if a note has a frequency of 440 Hz, the note an octave above it is 880 Hz, and the note an octave below is 220 Hz.
The human ear tends to hear both notes an octave apart as being essentially "the same", due to closely related harmonics. For this reason, notes an octave apart are given the same name in the Western system of music notation—the name of a note an octave above C is also C. The intervals between these notes are called ‘semitones’.
In this project we’ll take advantage of the 21/12 principle to generate the 12 notes in an octave.
Middle C has a frequency of 261.64Hz. An octave above Middle C, also known as Treble C, has a frequency 2 × 261.64Hz or 523.28Hz. There are 12 steps (semitones) between these two notes, and each step is 21/12 times the note before it.
In the image to the right, we entered 261.64 into the Calculator app. Then, in the next statement, the value is multiplied it by 21/12.
The handheld supplied Ans at the beginning (not shown) because the multiplication symbol requires something in front of it. Just pressing enter repeatedly creates the sequence of answers shown.
We will incorporate this repetitive principle into our program. If you continue the progression, the twelfth answer will be 523.28, exactly two times the starting value, because F × (21/12)12 = 2 × F.
Setting up the Program:
- Start a new program, and call it sound2.
- Add Text command, add opening and closing quotation marks, and type the text "The Musical Scale. Press enter."
- Assign the starting frequency, 261.64 to the variable f.
There are two assignment operators: := and →(sto). You can use either one:
f:=261.64 or 261.64 → f
- This variable will represent each of the 12 notes in the scale.
Setting up the For Loop:
- Add a For loop that goes from 1 to 12 (for the twelve notes).
- Add Send “SET SOUND statement from the Hub menu
- Add eval( ) for the variable f as shown.
Evaluating the frequency:
- Multiply f by 21/12 and store the result back into f.
f:= f * 21/12
- This statement takes the current value of f and changes it to the next higher note’s frequency on the scale.
- Run (ctrl+R) the program. Did you hear anything? Is it what you expected?
Modifying the Program:
Try adding the TIME parameter to the Send “SET SOUND command, and be sure to add an equivalent Wait statement to the program to let each note finish playing.
If a new command is received by the TI-Innovator™ Hub before it finishes its last task, then the device will process the new command instead of finishing the current one. Syncing the handheld with the TI-Innovator™ Hub is up to the programmer.
When you run this program you will not hear the usual 'do-re-mi-fa-sol-la-ti-do' sequence. That's only eight notes. The others correspond to the black keys on a piano. How can you get the program to only play the correct eight notes?
Consider adding a DispAt statement to show the frequency being played.
Application Computer MusicTeacher's Notes
You will use the random number generator on the TI-Nspire™ CX to create some computer-generated ‘music’.
- Use the For loop to control the number of notes
- Use the random number generator to create random musical notes
Your task is to complete a program that asks for the number of notes to play, and then uses a For loop to play the given number of random notes. As the note is being played, the frequency should be displayed on the handheld screen using DispAt.
In this application, we will use the randInt( ) function of the TI-Nspire™ to generate a random note on the musical scale.
- From the Calculator app, locate randInt( ) on menu > Probability > Random > Integer.
- This command takes two (or three) arguments.
- Enter a lower and upper value separated by a comma, and press enter.
- From then on, just up-arrow to the previous command, press enter to reuse it, and edit the two arguments to see the output of the function.
Combine this randInt( ) function with our musical notes formula to get the program to generate random notes based on the 21/12 relationship between the notes.
The important new part of the code is:
As you can see on the chart, the frequency of the note A in the first octave is 55Hz. The range 0 to 59 in the randint function represents the 60 notes in the chart. Notice the use of n in 2^(n/12) to generate the nth note from A in the first octave. When n is zero, then the frequency is 55Hz, since 20 is 1.
Use a Wait command to keep the handheld in sync with the music.
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3
Unit 3: BRIGHTNESS, IF, and WHILE with TI-Innovator™ Hub
Skill Builder 1 BRIGHTNESS MeasurementsTeacher's Notes
In this lesson, we investigate the onboard light sensor, BRIGHTNESS, and use the DispAt statement to show the sensor’s readings.
- Read the BRIGHTNESS sensor
- Introduce the While loop
In the previous lessons, we have only been sending instructions to the TI-Innovator™ Hub to have an impact on it’s built-in devices (LIGHT, COLOR, and SOUND).
In this unit, we will work with the onboard light sensor, and use the value in our program to create a ‘light meter’. The light sensor produces values in the range 0 to 100 in decimal form.
Obtaining the light level value from the TI-Innovator™ Hub requires TWO statements:
- Send “READ BRIGHTNESS”
- Get <var>
Setting up the Program:
- Start a new program. We call it bright1.
- We’ll use the variable b to store the BRIGHTNESS value, so we declare this variable to be Local to the program. This is optional.
- Select menu > Hub > Send “READ… > BRIGHTNESS. Press enter.
- Select menu > Hub > Get.
- Type the variable name b (No parentheses are used here.)
How it works:
- READ BRIGHTNESS tells the TI-Innovator™ Hub to read the brightness level and store that value in an onboard ‘buffer’.
- Get b is a handheld command to get the value from TI-Innovator™ Hub’s buffer. This statement transfers the value from the buffer on the TI-Innovator™ Hub to the variable
b in the TI-Nspire™ CX. The variable you use can be any legal variable name.
The While…EndWhile loop (menu > Control) is used to process a block of code while a condition is true. A condition is a logical statement that can be evaluated as true or false. The relational operators and the logical operators are found on the ctrl + =.
- The relational operators are =, ≠, , >, ≤, and ≥.
- The logical operators are and, or, not, and xor.
- These operators can be used together to build compound conditions such as x > 0 and y > 0.
We are going to use a simple While loop that stops when the BRIGHTNESS value is less than 1. To terminate the program, simply cover the light sensor on the end of the TI-Innovator™ Hub with your hand.
Adding a While Loop:
- Before the Send statement in your program, add the statements:
- This statement is used to initialize the loop. As long as the condition b > 1 is true, the loop continues reading the light sensor. Once it becomes false, such as when there is no more light coming into the sensor, the loop and the program terminate.
We want the Send and Get statements to go into a While loop. There's a convenient method for doing this:
- First, select the Send and Get statements by holding the [↑ Shift] key and using the arrow keys.
- Now, with the statements selected, use menu > Control > While
- This places While at the beginning of the statements and EndWhile below them.
- Add b>1 after the While so your loop looks like this so far:
Send "READ BRIGHTNESS"
Add the DispAt statement after the Get statement and before the EndWhile of the loop as shown by selecting menu > I/O > DispAt.
Display an appropriate message and the value of the variable b:
DispAt 1, “Brightness= “, b
- Run the program (ctrl+R) with the TI-Innovator™ Hub attached.
- You should see a sequence of values changing after the string "Brightness= ". The values change depending on the light intensity being read by the sensor.
- To stop the loop (and the program), cover the light sensor on the end of the TI-Innovator™ Hub so that the brightness value displayed is less than 1.
Skill Builder 2 BRIGHTNESS & LIGHT with IF, WHILETeacher's Notes
In this second lesson of Unit 3, we’ll develop an automatic light switch that responds to the ambient light, turning on when darkness falls and turning off when the amount of light increases.
- READ BRIGHTNESS
- Use a While loop
- Use If...Then...Else...End to turn the light on or off depending on BRIGHTNESS.
Now write a program that detects the BRIGHTNESS value and turns a light on when it gets ‘dark’. When the room lighting gets brighter, the light goes off. This is exactly how many automatic light switches and night lights work.
Our program will read the light sensor on the TI-Innovator™ Hub and turn the onboard LIGHT ON whenever the brightness value falls below a certain level and turn it off when the brightness is above that level.
Setting up the Program:
- Start a new program, and call it bright2.
- Add Text, a set of quotations marks, and the text "Auto Light: Press enter".
- Initialize the variable b by adding the statement b:=2.
- Add a While…EndWhile loop with the condition b>1. (The brightness value is very low.)
To terminate the loop and the program, cover the light sensor.
- In the While loop body, add Send “READ BRIGHTNESS” and Get b from the Hub menu as shown.
- Add DispAt 1, b to see the reading.
If statement will have two ‘blocks’ of code: one for when the condition is true and another for when the condition is false.
The structure of the multi-line statement is
If <condition> Then
<do this when true>
<do this when false>
You can add more blank lines anywhere by pressing enter.
Writing the Condition:
The brightness value is stored in the variable b and ranges from 0 to 100.
What is a good ‘dark’ value? We chose 25, but you can change it to any value between 0 and 100. Use your brightness meter from the previous lesson to decide on a lightness-darkness boundary value.
You could improve the program by using a Request statement for this ‘trigger’ value. Just be sure to use the Request statement before the While loop starts.
The '<' (less than) operator is accessed by pressing ctrl + =.
- Turn the LIGHT ON or OFF in the Then and Else blocks as shown.
- Run the program with the TI-Innovator™ Hub attached.
- Control the light hitting the sensor, and watch the LIGHT (the red LED on the Hub) turn on or off.
Add DispAt 2, “Light is ON” when the light is on and DispAt 2, “Light is OFF” when the light is off in the appropriate places in the program.
To stop the loop (and the program), cover the light sensor completely so that the brightness reading falls below 1.
One final note: The light will be ON when the program ends. Why? Add a statement to make sure that the light is off.
Skill Builder 3 BRIGHTNESS and COLORTeacher's Notes
In this third lesson of Unit 3, we’ll make use of the BRIGHTNESS value to control the COLOR LED.
- Read the light sensor and control either the COLOR LED brightness or the sound coming out of the speaker
- Use conversion formulas to change from BRIGHTNESS values to COLOR values
We will build a product that reacts to the brightness in the room. The brighter the room lighting, the brighter the COLOR LED. The tricky part here is converting the BRIGHTNESS value into an appropriate COLOR value. Think of this product as an auto changing (dimming or brightening) light bulb.
BRIGHTNESS b ranges from 0 to 100.
COLOR c (all three channels) can vary from 0 to 255.
How do we convert from b to c?
Setting up the Program:
- Start a new program, and name it bright3.
- Declare variables b and c to be local.
- Add the statement: DispAt 1, "Brightness to Color".
- Set the variable b to 2 as shown. b:=2
- Add a While…EndWhile loop to read the brightness using Send “READ BRIGHTNESS” and get the brightness variable with Get b.
- Add DispAt 2, "Brightness= ",b to monitor the value of b.
- Use the variable c to represent a COLOR value that we’ll send to all three channels of the COLOR LED. The conversion factor is 2.55. That is,
Check this formula with the two pairs of values given.
When b=0, then c=2.55*0 ==> 0;
and when b=100, then c=2.55*100 ==> 255.
- Add a Send "SET COLOR statement before the End of the loop. This statement will control the brightness of the color LED.
- Finally, complete the SET COLOR command by using eval(c) three times (once for each of the three color channels).
- When all three channels have the same value then the color of the LED is white, and the brightness of the LED changes depending on that value.
- Connect the TI-Innovator™ Hub, and run the program.
- Change the brightness by pointing the light sensor at different things. Watch the intensity of the COLOR LED on the TI-Innovator Hub.
- To end the while loop and hence the program, cover the sensor completely so that the value of b goes below 1.
You might want to add another DispAt statement to your program to monitor the values of b and c.
Application Lite MusicTeacher's Notes
In this application, you will create a program that lets you control the sound coming from the speaker based on changing the brightness sensed by the light sensor – hence, 'Lite Music!
- Write a program that converts brightness into sounds.
- Review musical note frequencies and the twelfth root of 2 principle.
Write a program that reads the BRIGHTNESS of a light sensor and plays a different sound depending on the brightness. There are two possible options for the sound:
- Play a frequency in the audible range (perhaps 100Hz – 1000Hz)
- Play a musical note (one of the specific harmonious sounds found on a piano or other musical instrument).
The first option would just play what sounds like ‘noise’. The second option will sound more like music, but the mathematics is a bit more complex.
This program makes the TI-Innovator™ Hub behave like a theremin. You can vary the amount of light visible to the BRIGHTNESS sensor by adding light (using a flashlight) or removing light (partially covering the sensor).
- Start a new program, and name it applic3
- Add DispAt 1, "Lite Music!".
- Initialize the variable b by adding the statement b:=2.
- Add a While loop to READ the BRIGHTNESS sensor and Get its value into a variable b.
- Add the statement to play a sound.
- Notice that we’re using the variable b for reading BRIGHTNESS and the variable f for playing the SOUND.
Your task is to complete the missing code that converts the BRIGHTNESS into an audible sound or a musical note.
For sound, use a frequency between 100 and 1000 Hz (or two frequencies of your choice).
For musical notes, try a range starting with A1 (55Hz) and going up 50 notes. (Refer to the activity studied in Unit 2, Skill Builder 3 (program sound2) which played the 12 notes in an octave.)
For the musical notes, you will need to convert your value to a whole number so that a note ‘number’ is correctly represented. You can use either the int( ) function or the round( ,0) function.
|x:=int(x) or x:=floor(x)
||gives the largest integer less than or equal to x.|
|x:=round(x,0)||rounds x to the nearest integer.|
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3
Unit 4: Make Rover Move!
Skill Builder 1 Your First Rover ProgramTeacher's Notes
In this lesson for Unit 4, you will learn about working in the Program Editor to write a program that makes the TI-Innovator™ Rover move.
- Use the TI-Nspire™ CX Program Editor
- Access the Rover (RV) submenus
- Use the Send command to CONNECT the TI-Innovator™ Rover to the TI-Innovator™ Hub
- Make the TI-Innovator™ Rover move FORWARD, BACKWARD, LEFT, and RIGHT
- The Rover commands are found by pressing menu > Hub > Rover (RV).
- Some portions of the final instruction, such as numeric values and optional parameters, are entered as normal keypad characters or selected from another Rover menu.
- Most Rover commands leave the cursor inside the quotation marks. This indicates that that there are more options to enter within the command. The TI-Nspire™ CX requires that quotation marks come in pairs.
Your first Rover command tells the TI-Innovator™ Hub to connect to the Rover:
Send “CONNECT RV”
RV is the name of the Rover device.
To create this statement:
- Press the menu key, and select the HUB menu.
- Then, select the Rover (RV) submenu.
- Select the Send “CONNECT RV” command near the bottom of the submenu.
The next command is the Text statement found in the menu > I/O menu. This command pauses the program and waits for the user to press the enter key.
- Press the menu key, and select the I/O menu.
- Select Text.
- Add an appropriate message after the Text command:
Text “Press enter to start.”
When running the program, if you hear a beep from the TI-Innovator™ Hub before (or while) you see “Press enter to start” it means that the CONNECT RV command was unsuccessful. Make sure the Rover is turned on.
Driving the Rover
- Press enter at the end of the Text statement in order to add the next command which will cause the Rover to move forward.
- Press menu > Hub > Rover (RV), and then select the Drive RV menu as shown to the right.
- Select FORWARD from the Drive RV menu.
Notice that the FORWARD command that is pasted into the program has the insertion cursor inside the quotation marks preceded by a space character. This is for adding optional parameters to the command.
- We add the number 1 here:
Send “RV FORWARD 1”
- In the Program Editor, press ctrl+R to ‘Run’ the program. This command (in the ‘Check Syntax & Store submenu) performs the ‘Check Syntax & Store’ operation and switches to a Calculator application and pastes the program name on the entry line. Supply any needed arguments to the program and press enter to run it. Be sure that there is about one foot of free space in front of the Rover.
The Text command displays a message and, when enter is pressed again, the Rover should move forward. But how far? Study the movement carefully and determine what FORWARD 1 means.
The Calculator application displays ‘Done’ when the program ends. Notice that the program actually ends before the Rover finishes moving. The handheld and the TI-Innovator™ Hub work at different rates.
- Edit the program, and add the statement Send “RV BACKWARD 1” below the FORWARD command by pressing menu > Hub > Rover > Drive RV > BACKWARD.
- Add the number 1 to the string.
- Run the program again (ctrl+R).
This time, the Rover should move forward a bit and then back to its original position. If it does, congratulations! You made the Rover move.
The next two commands in the Drive RV menu are LEFT and RIGHT.
- Add these two commands to your program, and run the program again.
Send “RV LEFT ”
Send “RV RIGHT ”
What do these instructions do?
Making it Travel
Study the program to the right, and predict what the Rover will do and where it will end up when the program ends.
- Enter these commands into your handheld, and run the program.
Did your program do what you expected? Can you make a program with only these commands that causes the Rover to make a rectangular pattern?
Skill Builder 2 Driving FeaturesTeacher's Notes
In this lesson, you will investigate some of the optional driving features. The four driving commands in Skill Builder 1 all left a space character after the driving command inside the quotation marks. This is because there are other options that you can supply to the commands. This lesson investigates those options.
- Extending the driving features of the Rover
- RIGHT and LEFT options
Parameters for FORWARD and BACKWARD
These driving commands have three optional parameters:
They are found in the menu > Hub > Rover (RV) > RV Settings menu partially shown at the right. Also, SPEED rates (UNITS/S and M/S) can also be accessed in this menu.
Using DISTANCE, SPEED and TIME
Some examples of different implementations of the FORWARD command:
- FORWARD DISTANCE # is the same as FORWARD #
- FORWARD DISTANCE # M moves Rover # Meters
- FORWARD # SPEED # where speed is between 1.4 and 2.3.
- Values outside this range result in a TI-Innovator™ Hub error.
- FORWARD TIME #
You can specify any two of these three options in the FORWARD and BACKWARD commands.
You can also use eval( ) if the value you want to use is stored in a handheld variable or if you want to use the result of an expression.
SPEED and TIME Program
- The program shown at the right has a command that moves the Rover FORWARD for a certain SPEED and TIME:
Send “RV FORWARD SPEED 2.3 TIME 2”
- Complete the program by providing the correct TIME so that the Rover returns to its starting position:
Send “RV BACKWARD SPEED 1.4 TIME ?”
Hint: DISTANCE = SPEED * TIME
RIGHT and LEFT Options
These commands by default turn the Rover RIGHT or LEFT 90 degrees but you can add a degree measure to the command to turn any angle (-360…360 degrees). Negative values are also permitted, so LEFT -90 is the same as RIGHT 90.
- Add a command to make Rover turn RIGHT 135 degrees. You have to key in the 135 inside the closing quotation mark. The word DEGREES is not needed but is available in the RV Settings menu for clarity.
You could also specify the angle measurement in RADIANS or GRADS but these units must be stated and are also found in the RV Settings menu.
Some examples are shown to the right. What is the final heading of the Rover after these three statements are processed?
Skill Builder 3 Options, COLOR and timingTeacher's Notes
In this third lesson for Unit 4, you will learn about turning to a specific angle heading, timing, and working with the COLOR LED on the Rover.
- Use the TO ANGLE command
- Use the RV.COLOR LED on the Rover
- Control timing on the handheld and the Rover
This lesson addresses three more features of the Rover:
- the TO ANGLE command (which is different from LEFT and RIGHT)
- lighting up the RV.COLOR LED onboard the Rover (labeled ‘Color’ on the top-front-left corner next to the battery level indicators)
- synchronizing your program with the Rover’s movements using Wait
The command Send “RV TO ANGLE <number>” is used to turn the Rover to a particular ‘heading’. When you send a command to connect the Rover, its heading is set to 0 degrees, which, in the mathematical world, is ‘East’ (facing from the origin toward the positive x-axis). In this world, North is 90 degrees, West is 180 degrees, and South is 270 degrees. See the diagram to the right.
Regardless of where the Rover is currently heading, the command Send “RV TO ANGLE 0” causes the Rover to turn to the direction that it was heading when the “CONNECT RV” command was issued.
The default angle measure is DEGREES but you can also specify RADIANS or GRADS (selected from the RV Settings menu).
Send “RV TO ANGLE 180”
Send “RV TO ANGLE 270”
Send “RV TO ANGLE 360”
Did the Rover do what you expected?
Syncing Your Program With Rover
Programs on the handheld are ‘Done’ before the Rover finishes moving. This is because the driving commands are stored in the TI-Innovator™ Hub faster than the Rover can process them. Driving commands are stored in a ‘queue’ and are processed by the TI-Innovator Hub when the Rover is ready for them.
In this activity, we’ll write a program to move in a random pattern and light up the RV.COLOR LED on the Rover while the Rover is moving. We’ll also make use of the TO ANGLE command and incorporate eval( ) to turn to the appropriate heading.
Setting Up the Program:
- Start the program with the CONNECT RV command.
- Add a For loop (menu > Control > For…EndFor) to have the Rover move in a random pattern. You can always add lines to the loop body if you need them.
- In the loop body, add the statement to move FORWARD.
Send “RV FORWARD 1”
- To have the Rover turn to a random heading, first add the command:
- Add the TO ANGLE statement to turn in the direction h.
Send “RV TO ANGLE eval(h)”
- Run the program now to see that:
- The Rover moves in a random pattern.
- The program is ‘Done’ almost immediately while the Rover still has to move.
Since the color LED on the TI-Innovator Hub is hidden inside the Rover, we are given another color LED on top of the Rover to control. The name of the Rover’s color LED is RV.COLOR and works using the same controls as the onboard LED. You can use any of the four commands in the menu > Hub > Rover (RV) > RV Color menu shown to the right.
Send “SET RV.COLOR 255 255 255” produces a white light.
Adding RV.COLOR to Your Program
- Add a RV.COLOR command to the loop body immediately before the FORWARD 1 command. The color values are up to you.
- Run the program again to see what happens. Notice that the LED lights up almost immediately and stays on.
Now, let’s try to get the LED to light up only while the Rover is moving FORWARD. This will require that we make the handheld Wait until each segment is completed and then turn the LED off while it is turning.
We need to add a Wait statement to our program to control when the LED is turned on and off.
- How long does it take Rover to move FORWARD 1? About 1 second?
Add a Wait 1 statement after the FORWARD 1 statement. You can adjust the value if it is not suitable for your environment. Recall that Wait is found in the menu > Hub menu.
- Run the program to test it.
Note that the LED still stays on. We have to turn the LED off after the Rover has finished moving.
- How long does it take the Rover to turn? About 1 second? Add a Wait 1 statement.
- After the Wait 1 statement, turn the LED off by adding Send “SET RV.COLOR 0 0 0”.
- Test your program. Did the Rover turn the light off at the right time?
We also need to wait while the Rover turns to a new heading to make sure the light has turned off.
- Add a Wait statement after the TO ANGLE statement. This Wait should be long enough to handle any turn from 0 to 360 degrees.
Can you make a different color at each corner? Hint: Use eval(something), and incorporate the value of h but be careful about the range of values permitted.
Make the turning wait time a function of the angle to be turned by observing the Rover’s turning direction when using TO ANGLE.
Application PolygonsTeacher's Notes
In this application for this unit is to program the Rover to make a polygon where the user enters the length of a side (in ‘Rover units’) and the number of sides of the polygon. The Rover will then make the polygon.
- Input statements
- Using eval( )
- Understanding polygon principles
- Working with COLOR and timing (Wait)
Recall that the purpose of eval( ) is to convert the value of a handheld variable or expression into a string to be sent to the TI-Innovator™ Hub. In the sound program shown at the right, the user enters a frequency for the variable frequenc. The eval(frequenc) function converts that number into a string representation that the TI-Innovator™ Hub can process.
Write a program that asks for the length of a side and the number of sides of a polygon and moves the Rover in that pattern. You can add a marker to the Rover and actually draw the polygon on a large sheet of paper. Remember that 1 unit is 10 cm.
Optional: Make the COLOR LED light up at the vertices of the polygon.
Some useful commands:
Request “LENGTH OF SIDE?”,L
Request “NUMBER OF SIDES?”,N
Send “RV FORWARD eval(L)”
Send “RV RIGHT <something>”
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3
Unit 5: Rover's Sensors
Skill Builder 1 Testing Rover's RangerTeacher's Notes
In this first lesson for Unit 5, you will learn about the TI-Innovator™ Rover’s Ultrasonic Ranger sensor and its ability to control the Rover’s motion.
- Use the READ RV.RANGER command to measure distance
- Using the command to change the Rover's motion
At the front of the TI-Innovator™ Rover is a sensor called the Ultrasonic Ranger. The Ranger measures the distance to an object in front of the Rover. This information can be used to control the Rover’s movement; if the Rover gets too close to an obstacle, it can be programmed to change direction to avoid the obstacle.
We’ll first write a test program to determine how the Ranger works and then, in Skill Builder 2, we’ll use that information to control the Rover’s movement.
The program will read the Rover’s Ranger value and display that value on the handheld screen. The Rover will not move in this program. You will move your hand in front of the Rover or hold the Rover in your hands and point it toward various obstacles to observe the measurements.
Start the Test Program
- Start with the Send “CONNECT RV” command from the menu > Hub > Rover (RV) menu.
The Main Loop
We’ll use a While loop to control the program. When the distance measured is less than a certain value, the program will end. We use the variable dist to record the distance measured.
- Initialize dist to be 1 (dist:=1).
- Select While…EndWhile from the menu > Control menu. Code the While loop to continue as long as dist is greater than 0.1.
The Loop Body
- The command to READ RV.RANGER is found in
menu > Hub > Rover (RV) > Read RV Sensors.
- Select Send “READ RV.RANGER”.
- Add the commands
to the loop body.
Getting a value from a sensor requires both the Send “READ RV…” command to get a value from the sensor into the TI-Innovator™ Hub and the Get command to get the value from the TI-Innovator™ Hub to the handheld. The Wait 0.25 command is used to slow the operation down to make the numbers easier to read and understand.
Displaying the Value
- From the menu > I/O menu, select DispAt. This statement is used to display the value of dist in a fixed position on the Calculator application screen.
- The DispAt statement requires (at least) two arguments: a line number from 1 to 8 and a variable or value to display. To display something closer to the center of the screen, add padding spaces after the variable or value. Example: DispAt 1, dist, “ “
Run the Program
- Store and run the program by pressing ctrl+R. While the program is running, the Calculator application screen displays a number. Move your hand in front of the Rover (or move the Rover) so that the Ranger can measure various distances. In what units are these distances measured? When will the program terminate?
Answer: The units are meters, and the program will end when the distance measured is less than 0.1 m, or 10 cm.
Skill Builder 2 Ranger and MovementTeacher's Notes
In the first lesson of Unit 5, you tested the Rover’s Ranger to see how to read the sensor and display a value. This lesson advances that testing to control the Rover’s motion.
- Use the READ RV.RANGER command to determine the distance to an obstacle
- Control the Rover’s movement when the Rover gets too close to an obstacle.
- Manage the timing of the Rover’s movement within the handheld program.
Let’s write a program to make the Rover move back and forth between two ‘walls’. We’ll start the Rover moving FORWARD, read the Ranger sensor and, when the Rover gets too close to the wall, make the Rover stop, turn around, and move FORWARD.
The Big Idea
In a For loop (which will eventually terminate)
Start the Rover moving FORWARD
While the distance is greater than about 25 cm
continue to monitor the Ranger sensor
End the While loop
STOP, turn RIGHT 180
End the For loop
- Begin the program in the usual manner.
- Add a For loop that will iterate ten times.
- Add a FORWARD 100 UNITS command to move ahead 10 meters (100 * 0.1m per unit)
As in the previous lesson, we’ll use the variable dist to represent distance from the Ranger to an obstacle.
- Initialize dist to 1, and insert a While dist > 0.25 loop.
Note the two Ends in the code: an EndFor and an EndWhile. This is called ‘nested loops’.
- We next insert the code into the body of the While loop.
- Add the Send “READ RV.RANGER” command.
- Use the Get command to store the value into the variable dist.
That completes the While loop. The Rover is moving FORWARD 10 meters and the While loop is monitoring the distance. If desired, add a DispAt statement to this While loop to display the current distance to make sure things are working properly.
When the While loop ends, this indicates that the Rover is too close to an obstacle. We’ll tell the Rover to STOP moving FORWARD and turn around. However, we do not need to tell Rover to move FORWARD again.
- After the End of the While loop but before the End of the For loop, add the RV STOP command and the RV RIGHT 180 command.
- Add the Wait 2 statement to give the Rover time to turn around before moving FORWARD again. (Remember that the FORWARD command is at the beginning of the For loop.)
- Test your program. When the Rover gets close to an obstacle, it should turn around and go in the opposite direction. Adjust values (minimum distance and Wait time), as needed, for your surface situation. If the Rover gets too close to the wall, then the back of the Rover could bump the wall when turning around.
Skill Builder 3 The COLORINPUT sensorTeacher's Notes
In this third lesson of Unit 5, we introduce the COLORINPUT sensor and use its value to cause the Rover to change direction.
- READ COLORINPUT
- Use the value to change the Rover's direction
The Rover has a COLORINPUT sensor on the bottom. The light shining at the floor is used by the sensor to better ‘see’ the color on the floor. We’ll write a program to turn Rover when it ‘sees’ a change in color. The color seen by the sensor is converted by the TI-Innovator™ Hub into one of nine possible values that represent colors:
1 = Red
2 = Green
3 = Blue
4 = Cyan
5 = Magenta
6 = Yellow
7 = Black
8 = White
9 = Gray
- We’ll use a For loop to cause the Rover to move and turn four times.
- We will use a While loop to look for a change in color but first we need to know what color the Rover currently ‘sees’. We READ RV.COLORINPUT and Get its value into the variable floor_color in the handheld.
- We then initialize another variable, color, to get the While loop started. color will hold the color the Rover sees while it is moving. Initially, we set color to be the same as floor_color. Then, we start the Rover moving FORWARD.
- We now code the While loop to compare color with floor_color because, inside the While loop, we’ll look for a change in the value of color.
- Don’t forget to add an EndWhile statement for the While loop.
- Inside the While loop, we monitor the color sensor as long as the Rover is moving. We store the color value in our variable color. The loop ends when color (the ‘current’ color) is different from floor_color (the ‘original’ color).
- At the end of the While loop, we tell the Rover to STOP and go RIGHT. Notice that these two statements fall between the EndWhile and the EndFor statements so the program causes the Rover to turn right four times when it detects a change in color of the surface.
Note: “RV STOP” cancels all drive commands.
- Add a FORWARD 1 command and a Wait 1 statement so that the Rover moves away from the colored spot before the program loops back to detect the new ‘original’ color (floor_color) again.
- Test your program on the floor on a surface of uniform color (white). Place an approximately 5 cm by 5 cm contrasting color (black) spot on the floor in the Rover’s path so that the COLORINPUT sensor will see it. When the Rover passes over the spot, it should stop, and then turn and go again. Pick up the color spot, and place it in front or the Rover again. This will have to happen four times for the program to complete.
Application The Winding RoadTeacher's Notes
In this application for Unit 5, you will write a program to get the Rover to follow a path on a piece of paper.
- Use COLORINPUT to detect and follow a curved path on paper
- Need a sample path on paper (See the PDF file of test pages.)
Write a program to get the Rover to follow a curved path on paper using the color sensor. The path will be described by two different colors like this:
The Rover will start at the left edge of the page and travel to the right following the curved path across the paper.
When the Rover sees RED, it will turn to the left a little and move forward a little. When the Rover sees WHITE, it will turn to the right a little and move forward a little.
Experiment with the turning angle and the moving distance to see how the Rover reacts to the different colors.
If your page is red and white as in the image above, you can use READ COLORINPUT.RED to see what values are given by each side of the paper. If you use a different color such as black, you can use READ COLORINPUT.GRAY (or .GREEN or .BLUE).
Here’s a program, colortest(), that you can use to test the Rover’s color sensor. See what values you should use in your program:
Send "CONNECT RV"
While getKey(0)=" "
DispAt 1,"Press any key to end."
Send "READ RV.COLORINPUT.RED"
DispAt 2,"Color value: ", r
Notice that the Rover does not move in this program. Use the above program to determine what the Rover sees on each side of the wavy line by observing the values of R that are displayed. Use this information to design your program. Test your program by placing the Rover on the left edge of the paper with the color sensor near the border between the red and white sides of the paper. Be sure Rover’s color sensor is over the paper. Your program should work no matter where the Rover begins.
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3
Unit 6: Coordinates with Rover
Skill Builder 1 Introduction to CoordinatesTeacher's Notes
In this first lesson for Unit 6, you will learn about the TI-Innovator Rover’s coordinate system and movement to coordinates.
- Understand the Rover coordinate system and initial position and heading
- Make the Rover move to a certain point on the coordinate plane
- Use mathematics to determine distance
The Rover has a ‘built-in’ coordinate system just like a graphing system. When you Send “CONNECT RV”, the Rover’s position on the coordinate grid is set to (0,0) and its heading is 0 degrees (points toward the positive x-axis).
FORWARD moves the Rover to the right.
LEFT turns the Rover 90 degrees counterclockwise.
Our program will tell the Rover to move to a point on its coordinate grid. We’ll use Request statements to enter values for x and y and then make the Rover drive to the point (x, y) and then move back to the origin.
- Start your program with the usual instructions.
- Include Request statements for x and y.
Recall that Request will display the message entered in quotes (the ‘prompt’).
- The Text statement gives you time to place the Rover at the origin and face the Rover in the ‘right’ direction.
- Add the Rover command to drive TO XY. The command is found in the menu > Hub > Rover (RV) > Drive RV menu. and will appear in your program as an incomplete statement.
Send “RV TO XY ”
The command will appear in your program as an incomplete statement.
- The x- and y-coordinates must be added and will be stored in the variables x and y, respectively. In order for the TI-Innovator™ Hub to use these values, you must use the eval( ) function twice.
- Add eval(x) eval(y) to the command.
Send “RV TO XY eval(x) eval(y)”
- Test your program now. Depending on the coordinate values you enter, the Rover will move to that position.
- Add a Wait command to let the Rover move to your point, and then tell the Rover to return to the origin. Simply use the numbers 0 and 0 separated by a space. We also add a statement to make the Rover point in its original direction (TO ANGLE 0).
- Test your program again. This time, the Rover should travel to your entered point and then return to the origin and face in the original direction.
Skill Builder 2 The Distance FormulaTeacher's Notes
In this lesson, you will use the TI-Innovator Rover to mark two points on its coordinate plane and determine the distance between the points using the distance formula.
- Move to two different points
- MARK the points with SOUND and COLOR and a marker
- Compute and display the distance between the two points
- Measure the distance between the points to confirm the calculation
- Estimate the error in the movement vs. the computation
This activity requires that a marker be used in the Rover’s marker holder to leave a trail on the paper.
We’ll write a program that marks two points on the plane and computes the distance between the two points. You will then measure the distance between the two points and compare the measurement with the calculation.
- Start your program with CONNECT RV and include the Rover command to set the unit distance to one inch (1 inch ≈ 0.0254 meters). The RV.GRID.M/UNIT command is found in the Rover (RV) > RV Setup menu.
Send “SET RV.GRID.M/UNIT .0254”
- Include four Request statements for the coordinates of the two points. Keep in mind that variables on the TI-Nspire™ CX can be multi-character so we can use the variables x1, y1, x2, and y2 for the coordinates.
Request “First x-coordinate (x1):”, x1
Request “First y-coordinate (y1):”, y1
Request “Second x-coordinate (x2):”, x2
Request “Second y-coordinate (y2):”, y2
We also use the customary Text statement to get ready to move.
Text “Press enter to start."
- Next, we get the Rover to move to the first point, Wait while the Rover moves, and then make a SOUND and LED color to indicate that the Rover has reached its point. We will also use a Text statement here and turn the LED off after pressing enter. Recall that the sound will play for only one second by default.
- Next, we get the Rover to move to the second point. A different sound and different LED color is used to indicate that the Rover has reached the point. A Wait statement is used here to keep the LED on for a few seconds before turning it off.
Tip: Copy and paste the code for moving to the first point and just edit for the second point.
- Finally, we program the handheld to compute and display the distance between the two points using the Distance Formula:
Be careful with the parentheses.
- Measure the second segment drawn (between the two points), and compare that measurement with the computed value. How does the measurement compare with the computed value? What is the percent error of the measurement? (measurement-distance)/distance*100
Skill Builder 3 Make the ShapeTeacher's Notes
In this lesson, you will write a program to make a pre-designed two-dimensional shape. You will program with lists and use a loop to plot points on paper.
- Define lists and use coordinate pairs stored in lists
- Design a 2-dimensional shape on paper and in the handheld
- Have the Rover draw the shape on paper (or simply follow the path).
This project requires the use of two lists that represent the x- and y-coordinates of the vertices of a shape of your own design. In this lesson we will use the design of the block letter T shown to the right. Our goal is to get the Rover to make this design using the marker or just follow the path if no marker is available.
- First, set up two lists containing the coordinate pairs. The lists to the right come from the block letter T shown previously. The x-coordinates are in the list xs and the y-coordinates are in the list ys. Feel free to design a different pattern.
Optional: Set up a plot to display your data to confirm that your data is correct.
- Now, we can write a program so that the Rover will draw the shape. Start in the usual manner and, optionally, set the M/UNIT value to a smaller value so that the drawing is not too large. Select menu > Hub > Rover (RV) > RV Setup > RV.GRID.M/UNIT.
Remember that 0.01 makes the unit 1 cm. If you want the unit to be 1 inch, use 0.0254.
Send “SET RV.GRID.M/UNIT .0254”
- We use a For loop to process each element of the two lists. Remember that For requires three arguments, the loop control variable, i, a starting value, 1, and an ending value, dim(xs). EndFor is needed at the bottom of the loop body.
For i, 1, dim(xs)
Note: dim(xs) is the number of elements in the list xs.
- The loop body (the code inside the For loop) consists of just one statement that tells the Rover to go to each point in the lists in order.
Send "RV TO XY eval(xs[i]) eval(ys[i])"
- After entering the code, run the program, and see if your shape is drawn correctly.
Application Random WalkTeacher's Notes
Overview: Explorations with random numbers can lead to fascinating observations. This application gives you opportunities to explore more probability oddities and to program the Rover to move around on a grid.
- Use coordinate movement to simulate a ‘random walk’
- Use counters and accumulators in a program
- Use compound conditions with not and and
A ‘random walk’ is a computer programming experiment. This activity ties together several different programming skills.
Suppose your town’s streets are laid out in a square grid pattern and that your school is located at (0,0) on the grid. Your home is at (7,3), which represents 7 blocks east and 3 blocks north of the school. (Consider changes to this position.) The image to the right is a plot of these two points.
Starting at the school, you walk one block in a random direction (north, south, east, or west). At each intersection you then walk one block in a random direction again. Will you ever make it home? How many blocks will you walk before getting home? Will you quit from exhaustion before you get home?
Planning is an important part of coding. Think about what the Rover can do and what your programming language can do.
Bear in mind that, when working with random numbers, we are at the mercy of the machine. It may take a long time for the Rover to reach home, so we’ll add a stipulation that the Rover is allowed to walk only a limited number of blocks before quitting.
- Begin this program with the usual initial statements. Consider setting the Rover’s grid size to something smaller than the default 10 cm.
Recall that the command is found in menu > Hub > Rover (RV) > RV Setup and it changes the Rover’s ‘unit’ of movement (used in FORWARD 1) from 10 cm to something else, allowing for more grid points in a smaller space.
- Store the home location (7,3) and the starting number of blocks walked (0) in the variables home_x, home_y and blocks, respectively. The variable blocks will be used to keep track of the number of blocks the Rover walks and will be used to stop the program if the Rover walks too far. The Rover quits from exhaustion when it walks a specified number of blocks.
We used 20 blocks walked as a value for the exhaustion distance and initialized quit with the value 20.
- The Rover arrives home when its position, which we refer to as (x, y), is (7, 3). Initialize both of the variables, x and y, to be zero.
The Main Loop:
- The main loop of the program consists of a While with two conditions to be addressed. The conditions are making it home (when x=home_x and y=home_y) or quitting from exhaustion (when blocks=quit).
The While loop continues as long as those conditions are false, so we set up the opposite conditions:
While blocks<quit and not(x=home_x and y=home_y)
Remember that fixed values related to the problem are stored in quit, home_x, and home_y.
not( ) is used to ensure that the program continues as long as the Rover is not ‘home’. Logically, and not is the ‘opposite’ of or.
- Remember to include the EndWhile statement if you’re typing code by hand.
Inside the Loop:
- Increment blocks (the number of blocks walked):
- Pick a random direction (north, south, east, or west):
- The Rover’s TO ANGLE command turns the Rover to an ‘absolute’ direction: 0 is east, 90 is north, 180 is west, and 270 is south
- randInt(0,3) gives a random Integer from the set 0, 1, 2, and 3
- Multiply that value by 90 to get 0, 90, 180, or 270
- The statement to pick a random direction dir is:
- Turn the Rover to the Angle dir: Send “RV TO ANGLE eval(dir)”.
- Move the Rover forward 1 unit (1 block in our simulation): Send “RV FORWARD 1”.
- Update the Rover’s position in the program:
- If the Rover goes north, then increase y by 1
- If the Rover goes east, then increase x by 1
- If the Rover goes south, then decrease y by 1
- If the Rover goes west, then decrease x by 1
Include some Wait commands to keep the program in sync with the Rover’s movements. Turning takes time and moving forward takes time. The Wait times depend on the angle of the turn and the distance travelled so you many need to experiment with the Wait values
After the Loop:
The loop ends in one of two ways:
- If blocks=quit, then the Rover quits walking from exhaustion. Play a sad song, display a red color on the Rover’s LED, and display “Rover quit from exhaustion!” on the handheld screen.
- Otherwise, the Rover must have made it home. Play a happy song, display a green color on the LED, and display a “Rover made it home!” message on the handheld screen.
- In either case, report the number of blocks walked.
- Remember to use EndIf at the end of the ‘If… Then… Else… EndIf’ structure.
Can you get the Rover to do a ‘happy dance’ when it arrives home?
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3