10 Minutes of Code:
TI-Nspire™ CX Technology &
TI-Innovator™ 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 Program
Download Teacher/Student DocsIn 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.
Objectives:
- 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
Step 1
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.
Step 2
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.
Step 3
The cursor is now in the dotted box between Prgm and EndPrgm.
The parentheses after the program name are used for adding optional parameters.
Step 4
Your program consists of only one line of code:
Send(“SET LIGHT ON TIME 5”)
LIGHT is the name of the red LED.
Step 5
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.
Step 6
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”
Step 7
The complete program is shown to the right.
The Send command will send the string (the text in quotes) to the TI-Innovator™ Hub.
Step 8
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.
Step 9
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.
Step 10
Extensions:
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 Color
Download Teacher/Student DocsIn this second lesson for Unit 1, you will learn about input to a program and controlling the COLOR LED on the TI-Innovator™ Hub.
Objectives:
- Use arguments to a program
- Control the COLOR LED
Step 1
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.
Step 2
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.
Step 3
- 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.
Step 4
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.
Step 5
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.
Step 6
- 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’.
Step 7
- Select menu > Hub > Send “SET… > COLOR to paste the first part of the command into the program.
Step 8
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.
Step 9
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.
Step 10
- After the Send statement, add a Wait statement to wait a few seconds. Remember to provide a number of seconds.
Step 11
- Finally, add another Send “SET COLOR … statement to turn the color LED off.
- Use three 0’s to turn off all three colors.
Step 12
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 SOUND
Download Teacher/Student DocsIn 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.
Objectives:
- Use the Request statement
- Control the frequency and timing of the speaker (SOUND)
Step 1
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’.
Step 2
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.
Step 3
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.
Step 4
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.
Step 5
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 Light
Download Teacher/Student DocsWrite a program that controls a traffic light.
Objectives:
- Control the COLOR LED to simulate a traffic light using a single bulb
- Create a sequence of statements with proper timing controls
Step 1
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.
Step 2
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.
Step 3
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.
Step 4
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
- Application
Unit 2: For Loops with TI-Innovator™ Hub
Skill Builder 1 Blink the LIGHT
Download Teacher/Student DocsIn 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.
Objectives:
- Learn about the For loop
- Make the light blink
- Use the DispAt statement for text and variables
Step 1
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.
Step 2
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.
Step 3
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.”
Step 4
- 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.
Step 5
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.
Step 6
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.
Step 7
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 COLORs
Download Teacher/Student DocsIn 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.
Objectives:
- Use For loops to control each of the three color channels on the COLOR LED
Step 1
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.
Step 2
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.
Step 3
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.
Step 4
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.
Step 5
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.
Step 6
- 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.
Step 7
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)
or
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.
Step 8
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?
Step 9
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.
Step 10
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.
Step 11
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?
Step 12
Extension: Use DispAt in the appropriate places to show the current values of the red, green and blue channels. You'll need one statement in each loop but they can all be the same statement. Try using select, copy and paste tools.
Skill Builder 3 Loop through the musical notes
Download Teacher/Student DocsIn 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.
Objectives:
- Explain the ‘twelfth root of two’ relationship of the musical scale
- Write a program that plays successive notes in a scale
Step 1
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.
Step 2
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.
Step 3
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.
Step 4
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.
Step 5
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.
Step 6
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?
Step 7
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 Music
Download Teacher/Student DocsYou will use the random number generator on the TI-Nspire™ CX to create some computer-generated ‘music’.
Objectives:
- Use the For loop to control the number of notes
- Use the random number generator to create random musical notes
Step 1
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.
Step 2
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.
Step 3
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
- Application
Unit 3: BRIGHTNESS, IF, and WHILE with TI-Innovator™ Hub
Skill Builder 1 BRIGHTNESS Measurements
Download Teacher/Student DocsIn this lesson, we investigate the onboard light sensor, BRIGHTNESS, and use the DispAt statement to show the sensor’s readings.
Objectives:
- Read the BRIGHTNESS sensor
- Introduce the While loop
Step 1
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>
Step 2
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.
Step 3
- Select menu > Hub > Get.
- Type the variable name b (No parentheses are used here.)
Step 4
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.
Step 5
While Loop:
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.
Step 6
Adding a While Loop:
- Before the Send statement in your program, add the statements:
- b:=2
- 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.
Step 7
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.
Step 8
- Add b>1 after the While so your loop looks like this so far:
While b>1
Send "READ BRIGHTNESS"
Get b
EndWhile
Step 9
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
Step 10
- 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, WHILE
Download Teacher/Student DocsIn 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.
Objectives:
- READ BRIGHTNESS
- Use a While loop
- Use If...Then...Else...End to turn the light on or off depending on BRIGHTNESS.
Step 1
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.
Step 2
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.
Step 3
- 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.
Step 4
If Statements:
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>
Else
<do this when false>
EndIf
You can add more blank lines anywhere by pressing enter.
Step 5
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 + =.
Step 6
- 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.
Step 7
Optional:
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 COLOR
Download Teacher/Student DocsIn this third lesson of Unit 3, we’ll make use of the BRIGHTNESS value to control the COLOR LED.
Objectives:
- 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
Step 1
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?
Step 2
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.
Step 3
- 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,
c:=2.55*b.
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.
Step 4
- 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.
Step 5
But wait! The effect is wrong! The darker the room lighting, the brighter the LED should be! How can you reverse the effect?
Another Challenge: Consider changing the program so that different brightness values produce different colors.
Application Lite Music
Download Teacher/Student DocsIn 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!
Objectives:
- Write a program that converts brightness into sounds.
- Review musical note frequencies and the twelfth root of 2 principle.
Step 1
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).
Step 2
Getting Started:
- 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.
Step 3
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
- Application
Unit 4: Make Rover Move!
Skill Builder 1 Your First Rover Program
Download Teacher/Student DocsIn 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.
Objectives:
- 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
Step 1
Getting Started
- 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.
Step 2
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.
Step 3
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.
Step 4
- 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.
Step 5
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.
Step 6
- Select FORWARD from the Drive RV menu.
Step 7
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”
Step 8
- 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.
Step 9
Driving Backwards
- 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.
Step 10
Turning
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?
Step 11
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 Features
Download Teacher/Student DocsIn 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.
Objectives:
- Extending the driving features of the Rover
- RIGHT and LEFT options
- Wait
Step 1
Parameters for FORWARD and BACKWARD
These driving commands have three optional parameters:
- SPEED
- TIME
- DISTANCE
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.
Step 2
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.
Step 3
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
Step 4
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?
Step 5
Write a program to make the Rover drive along the path of an equilateral triangle.
Start with:
Send “CONNECT RV”
Send “RV FORWARD ?”
Send “RV LEFT ?”
Or, use a loop.
Skill Builder 3 Options, COLOR and timing
Download Teacher/Student DocsIn 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.
Objectives:
- Use the TO ANGLE command
- Use the RV.COLOR LED on the Rover
- Control timing on the handheld and the Rover
Step 1
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
Step 2
TO ANGLE
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).
Step 3
Try this:
Wait 2
Send “RV TO ANGLE 180”
Wait 2
Send “RV TO ANGLE 270”
Wait 2
Send “RV TO ANGLE 360”
Did the Rover do what you expected?
Step 4
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.
Step 5
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.
Step 6
- 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:
h:=randInt(0,360) - 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.
Step 7
RV.COLOR
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.
Step 8
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.
Step 9
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.
Step 10
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?
Step 11
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.
Step 12
Extension
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.
Additional Challenge:
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 Polygons
Download Teacher/Student DocsIn 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.
Objectives:
- Input statements
- Using eval( )
- Understanding polygon principles
- Working with COLOR and timing (Wait)
Step 1
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.
Step 2
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
For I,1,N
Send “RV FORWARD eval(L)”
Send “RV RIGHT <something>”
EndFor
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3
- Application
Unit 5: Rover's Sensors
Skill Builder 1 Testing Rover's Ranger
Download Teacher/Student DocsIn 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.
Objectives:
- Use the READ RV.RANGER command to measure distance
- Using the command to change the Rover's motion
Step 1
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.
Step 2
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.
Step 3
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.
Step 4
The Loop Body
- The command to READ RV.RANGER is found in
menu > Hub > Rover (RV) > Read RV Sensors. - Select Send “READ RV.RANGER”.
Step 5
- Add the commands
Get dist
Wait 0.25
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.
Step 6
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, “ “
Step 7
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 Movement
Download Teacher/Student DocsIn 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.
Objectives:
- 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.
Step 1
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
Step 2
- 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)
Step 3
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’.
Step 4
- 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.
Step 5
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.
Step 6
- 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 sensor
Download Teacher/Student DocsIn this third lesson of Unit 5, we introduce the COLORINPUT sensor and use its value to cause the Rover to change direction.
Objectives:
- READ COLORINPUT
- Use the value to change the Rover's direction
Step 1
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
Step 2
- Begin the program in the usual manner.
Step 3
- We’ll use a For loop to cause the Rover to move and turn four times.
Step 4
- 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.
Step 5
- 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.
Step 6
- 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.
Step 7
- 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).
Step 8
- 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.
Step 9
- 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 Road
Download Teacher/Student DocsIn this application for Unit 5, you will write a program to get the Rover to follow a path on a piece of paper.
Objectives:
- Use COLORINPUT to detect and follow a curved path on paper
- Need a sample path on paper (See the PDF file of test pages.)
Step 1
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.
Step 2
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).
Step 3
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:
Define colortest()=
Prgm
Send "CONNECT RV"
While getKey(0)=" "
DispAt 1,"Press any key to end."
Send "READ RV.COLORINPUT.RED"
Get r
DispAt 2,"Color value: ", r
EndWhile
EndPrgm
Step 4
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
- Application
Unit 6: Coordinates with Rover
Skill Builder 1 Introduction to Coordinates
Download Teacher/Student DocsIn this first lesson for Unit 6, you will learn about the TI-Innovator Rover’s coordinate system and movement to coordinates.
Objectives:
- 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
Step 1
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.
Step 2
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.
Step 3
- 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.
Step 4
- 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.
Step 5
- 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 Formula
Download Teacher/Student DocsIn 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.
Objectives:
- 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
Step 1
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”
Step 2
- 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."
Step 3
- 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.
Step 4
- 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.
Step 5
- 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 Shape
Download Teacher/Student DocsIn 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.
Objectives:
- 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).
Step 1
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.
Step 2
- 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.
Step 3
- 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”
Step 4
- 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)
EndFor
Note: dim(xs) is the number of elements in the list xs.
Step 5
- 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 Walk
Download Teacher/Student DocsOverview: 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.
Objectives:
- Use coordinate movement to simulate a ‘random walk’
- Use counters and accumulators in a program
- Use compound conditions with not and and
Step 1
A ‘random walk’ is a computer programming experiment. This activity ties together several different programming skills.
The Problem:
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?
Step 2
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.
Step 3
Initializing Variables:
- 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.
Step 4
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.
Step 5
Inside the Loop:
- Increment blocks (the number of blocks walked):
blocks:=blocks+1 - 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:
dir:=90*randInt(0,3)
Step 6
- 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
Step 7
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
- Application
Unit 7: The RGB Array
Skill Builder 1 Light Them Up
Download Teacher/Student DocsIn this first lesson of Unit 7, you will learn to control the sixteen color LEDs on the TI-RGB Array as a group and individually.
Objectives:
- Light up ALL LEDs and make them blink in unison
- Use another loop to light up and turn off the LEDs one at a time
Note: The “TI RGB Array Sim” that is shown to replicate the lights on the circuit board, has been created, and used for demonstration purposes. This tool is not available for purchase or distribution by TI. Caution: rapidly flashing lights may be disturbing for some students, so it is wise to use Wait statements to slow things down a bit.
Step 1
back
BB ports
The TI-RGB Array is a circuit board with 16 color LEDs and a controller chip and comes with a short 4-wire cable. It connects to the TI-Innovator using the cable wires that plug into breadboard (BB) ports on the TI-Innovator. Follow the wiring instructions on the back of the board to connect it to the TI-Innovator and connect the TI-Innovator to your TI-Nspire CX.
Step 2
Your first program will make all 16 LEDs on the RGB Array blink 10 times. There are two instructions that control the Array:
Send(“CONNECT RGB”)Send(“SET RGB ALL r g b”) or Send(“SET RGB # r g b”)
# is an LED number (0 to 15) or eval(var or expression)
Step 3
- Start a new program - we call it blink( ) - and add the statement
Send “CONNECT RGB” by pressing menu > HUB >
Send “CONNECT-Output > RGB and add the closing quotation mark:
Send “CONNECT RGB”
Step 4
- Add a For loop by pressing menu > Control > For...EndFor
The loop parameters are: a variable (we used i) varying from 1 to 10 or an upper value of your choice:
For i,1,10
But remember that when running the program you must wait for the program to end before doing anything else. There will be a better way of ending programs at any time in the next Skill Builder.
Step 5
- In the loop body add two Send statements: one to turn all the LEDs on and one to turn them all off. Follow each with a Wait statement:
Send “SET RGB ALL 255 255 255” white Wait 0.5 Send “SET RGB ALL 0 0 0” off Wait 0.5
For the Send statements press menu>HUB>Send “SET… > RGB and complete the rest of both statements manually.
Add the two Wait statement using menu>HUB>Wait and provide a time value.
As with the COLOR LED on the Innovator and RV.COLOR on Rover, there are three color values: red, green, and blue, each varying from 0 to 255. We used white LED’s but you can create any color you like.
Step 6
- Press ctrl-R to run the program and watch the LED’s on the RGB Array blink.Modify the program to display your favorite color.
Each of the sixteen LED’s can be controlled individually. Use the LED number (0 to 15) in place of ALL as in
Send “SET RGB 5 255 0 0” turns LED #5 to red.
If using a variable, then remember to use the eval( ) function found on the Hub menu. The next step illustrates this technique.
Step 7
To control the LEDs one at a time, use an inner For loop and modify the Send commands to make use of the inner loop variable in place of ALL in the Send statements.
- To ‘wrap’ the Send and Wait statements in another For loop, first select the four statements by placing the insertion cursor at the beginning of the block and press [shift] [down arrow]. Then…
Step 8
- With the block selected, add the For loop by pressing menu > Control > For…EndFor. The selected text will be inside the new For and EndFor statements.
- Complete the For statement. Note that the LEDs are numbered 0 to 15.
- Change ALL to eval( j ) found on menu>Hub
For i, 1, 5 use a smaller loop to go faster
For j, 0, 15
Send “SET RGB eval( j ) 255 255 0” yellow
Wait .1 make this smaller to go faster, too
Send “SET RGB eval( j ) 0 0 0”
Wait .1 make this smaller to go faster, too
EndFor
EndFor
Step 9
eval( is found on menu > HUB
We also made the outer loop smaller and decreased the Wait value to 0.1 to speed things up.
Run the program to see the effect.
Skill Builder 2 A Rainbow of Color
Download Teacher/Student DocsIn this lesson, you will generate random colors on each of the LEDs on the TI-RGB Array.
Objectives:
- Use getKey( ) to end a program
- Use randInt( ) to light a random LED in a random color
Step 1
We will use the random number generator randInt( ) to make random LEDs light up in random colors.
Step 2
- Start a new program - we called it rainbow() - and add
Send “CONNECT RGB”
Using menu > HUB > Send “CONNECT-Output… and select RGB from the next menu.
Type the closing quote and parenthesis.
Step 3
- Add a While… EndWhile loop using menu > Control > While...EndWhile
Step 4
- The loop will end when the [esc] key is pressed. The condition is:
While getkey(0) ≠ “esc”
≠ is found on ctrl =
type the quotes using [ctrl] [*] then the letters esc.
Step 5
- In the loop body write four statements to assign random integers to four variables representing the LED number and the red, green, and blue values.
led := randInt( 0, 15)
red := randInt( 0, 255)
green := randInt( 0, 255)
blue := randInt( 0, 255)
Step 6
- Add the Send statement to control one of the TI-RGB Array LEDs:
Send “SET RGB eval(led) eval(red) eval(green) eval(blue)”
and a Wait statement to slow the lights down:
Wait .25
Step 7
- Press ctrl-R to run the program to see a wide variety of colors blinking. Press [esc] to stop the program. Notice that the LEDs are still lit even though the program has ended.
Fix this by turning them off just after the EndWhile loop statement by adding the statement:
EndWhile
Send “SET RGB ALL 0 0 0”
EndPrgm
Skill Builder 3 Sequencing
Download Teacher/Student DocsIn this lesson, you will make the top row of LEDs light up from right to left and the bottom row light up from left to right at the same time.
Objectives:
- Use any key to end the program
- Use a For...EndFor loop to control both rows of LEDs at once
Step 1
Take a close look at the numbers on the LEDs on the TI-RGB Array. The top row goes from 0 to 7 (right to left) and the bottom row goes from 15 to 8 (left to right). If we use a For i, 0, 7 statement to light up the top row, then what expression can we use to light up the bottom row in the opposite direction?
Step 2
- Start a new program – we called it sequence() - and add the statements
Send “CONNECT RGB ”
For i, 0, 7
EndFor
This code will control the top row of LEDs.
Step 3
- In the For loop, write the three statements to turn on light # i (we are using yellow), wait a moment, then turn it off:
Send "SET RGB eval( i ) 255 255 0"
Wait .2
Send "SET RGB eval( i ) 0 0 0"
Step 4
- Test the program. You should see the top row of LEDs light up from right to left once.
Step 5
We need to make the bottom row light up going from left (15) to right (8) in the same loop.
When i varies from 0 to 7, what expression varies from 15 to 8?
Answer: 15 – i (do the mathematics!)
- Right after lighting up Led # i also light up LED # 15-i with the statement
Send “SET RGB eval(15 - i) 255 255 0”
and turn it off after the Wait statement, too.
Step 6
- Run the program again. You should see two LED’s light up, the top row going from right to left and the bottom row going from left to right. The program ends after one pass.
Next, create a loop to make the program continue until a key is pressed.
Step 7
We will use an unusual control structure here: Loop…EndLoop.
This structure must contain an Exit or a Stop statement somewhere in the loop body. Our exit/stop will be triggered by the [esc] key by using getKey(0) in an If statement.
Exit transfers control to the first statement after the EndLoop statement.
Stop ends the program immediately.
Do not access this structure just yet.
Step 8
- First, select the entire For... EndFor loop by:
Place the cursor in front of the word For
Hold [shift] and press [down arrow] to select everything down to and including EndFor
Step 9
- Now choose the Loop...EndLoop structure from
Menu > Control > Loop...EndLoop
The Loop statement appears above For and EndLoop appears after EndFor.
Step 10
- In the For loop at the bottom add the simple If statement:
If getKey(0) ≠ “ ” : Stop
Which means that if a key is pressed, Stop the program. getKey(0) does not pause the program but getKey(1) does. Try placing this If statement in different places inside the Loop loop to see the different effects but watch out for an ‘infinite’ loop!
The colon character (:) is found on the punctuation key to the right of the letter g.
Step 11
- Run the program and notice the effect: does it appear that the lights are moving ‘around’ the board? When the program is running press any key to end it.
Application Smart Lights
Download Teacher/Student DocsIn this final lesson, you will develop a program that uses the BRIGHTNESS sensor on the TI-Innovator to control the number of LEDs lit up on the TI-RGB Array.
Objectives:
- Use a sensor to control the TI-RGB Array
- Use a keypress to terminate the program
Step 1
The TI-Innovator has an onboard BRIGHTNESS sensor. Imagine a lighting system that adapts to the brightness of the room: When the room is bright, little extra illumination is needed. As the room darkens, the number of extra lights needed increases. Using the TI-RGB Array, we can simulate this lighting system by making more LEDs light up as the BRIGHTNESS decreases. This application will build that lighting system simulation.
Step 2
- Begin a new program – we call it britelites() - with the usual starting commands:
Start with Send “CONNECT RGB”
and write a While loop the monitors the keypress so that the loop ends when [esc] is pressed:
While getKey(0) ≠ “esc”
After the loop, make sure all LED’s are turned off using
Send “SET RGB ALL 0 0 0”.
Step 3
- Start the body of the While loop by reading the BRIGHTNESS sensor using:
Send “READ BRIGHTNESS”
Get b
Step 4
- The BRIGHTNESS sensor gives a value from 0 to 100, but you can customize this range for your own lighting situation. Sometimes 0 is difficult to attain so we’ll settle for 5 as a lower bound and we decided that 50 is ‘bright enough’. Note the two If statements we added to the program:
If b < 5 : b := 5
If b > 50 : b := 50
Step 5
You may choose to use different limits depending on your lighting situation, but the maximum range is 0 to 100. You may find a smartphone with a ’flashlight’ helpful to get a wider range of values from the sensor.
Your task is to devise a ‘conversion formula’ to change the brightness value into a number of LEDs to light up. Convert the brightness value b, ranging from 5 to 50 into an appropriate number of LEDs n, ranging from 16 to 0. Use the int( ) function since we always want to control a whole number of LEDs.
Hint: The equation of the line through two points (a, b) and (c, d) is:
y = m * (x - a) + b where m is the slope of the line and
m = (d – b) / (c – a)
Our two points are (5,16) and (50,0). Yours might be different.
Step 6
- Use a For I, 1, n loop to light up the desired number of LED’s and then write another loop to turn off any remaining LEDs. This will ensure that only the needed LEDs are lit without causing them to blink. Remember that the first LED is number 0. Use eval(i - 1) to properly address the LEDs.
- Your program should properly handle the two extreme conditions: when no LEDs should be lit and when all the LEDs should be lit.
- Skill Builder 1
- Skill Builder 2
- Skill Builder 3
- Application