10 Minutes of Code:
TI-Nspire™ CX Technology &
Short, easy-to-teach activities design to be completed in order, using TI-Npsire™ 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™ 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 calculator
Connect the TI-Innovator™ Hub to the TI-Nspire™ CX. 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 calculator with the TI-Innovator™ Hub, you will be learning to program in two separate but connected worlds: the calculator and the TI-Innovator™ Hub.
When writing a program on the calculator, you will use the Program Editor found on the Calculator application 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.
Our first program will tell the TI-Innovator Hub to turn on the red LIGHT (LED) for 5 seconds.
- To begin writing a new program in the Calculator app, press menu > Functions and Programs > Program Editor > New.
- Type a name for the program (we use the name light1 here), and press enter.
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 menu item.
The Hub> toolbox contains statements related to programming the TI-Innovator™ Hub. These statements can be typed in by hand, but it is usually easier to select them from the menu.
When you choose Send “SET, the next submenu contains the LIGHT object. Here you can find ON and TIME on the settings submenu.
- Complete the statement by completing the rest of the command:
Send(“SET LIGHT ON TIME 5”)
- Find ON and TIME on menu > Hub > Settings.
The complete program is shown to the right.
The Send command will send the string (the text in quotes) to the TI-Innovator™ Hub.
To run the program:
- Press ctrl+B to ‘Check Syntax & Store’ the program.
- Switch to the Calculator app.
- Press VAR, and select the program name from the list. This pastes the program name onto the home screen.
- Make sure your TI-Innovator Hub is connected to the calculator.
- Press [ENTER] to run the program.
The calculator 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 calculator 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.
- Add a blank line to the program by placing the cursor at the end of the Send statement and pressing enter.
- You’ll find Wait on the Hub menu.
- Add the statement Wait 5 just before EndPrgm.
Quit the editor, and run the program again.
If the program was the last item on the Calculator app, simply press [ENTER] to rerun it. 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 timing using the Wait command in the calculator.
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”.
To get a particular color, you have to mix the right amounts of the three colors red, green, and blue. All other colors are possible with the right mix of these three colors.
First let’s control the COLOR LED right from the Calculator app:
- From menu > Functions & Programs > I/O, select the Send command.
- After the keyword Send, type both leading and trailing quotation marks (ctrl-[X]).
- Inside the quotation marks, type
and three numeric values separated by spaces representing the amount of red, green, and blue to light up.
- These three numbers can be between 0 and 255. The higher the number, the brighter the color. See some examples to the right.
Notice that the LED stays lit until you change it. A program can help control the LED more precisely by turning it off before the program ends.
- To start a new program from the Calculator app, select menu > Functions & Programs > Program Editor > New….
- 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 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’.
Setting up the Color Program
- 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 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 calculator 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.
- Press ctrl-B to check and store the program.
Run the Program:
- With the TI-Innovator™ Hub connected, in the Calculator app, press [VAR], and select the program name (or simply type the program name and a set of parentheses).
- Inside the parentheses, provide three numbers representing the amount
of red, green, and blue light to mix, and press enter.
- The color LED lights up for the number of seconds you specified in the Wait statement and then turns off.
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 In this sound program, we’ll use the Request statement.
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.
- Add the prompt “Frequency? ” and a comma after the keyword Request.
- Then type the variable that will represent the frequency, freq.
- 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-B to store the program.
Run the program
When you run this program, a dialog box appears as a result of the Request statement.
- 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 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 yellow 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 calculator. 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.
Setting up the title screen
- Begin a new program, and call it APPLIC1.
- Get 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 calculator 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 so that a blind person (pedestrian, not driver!) can tell which color the light is.
- 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 calculator through a program that makes the LED light blink while displaying information on the calculator screen.
- Learn about the For loop
- Make the light blink
- Use the Disp 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 Disp by selecting menu > I/O and selecting 1:Disp.
- Within quotation marks, add the text “Blink” as shown.
- Add Request by selecting menu > I/O > 1: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 > I/O > 5: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 calculator to display the number of the blink.
We’ll start the loop body with Disp I, the loop control variable.
We will now add statements to turn the light ON and OFF as shown on the next step.
- 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 calculator 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-B), and run the program in 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 more input statements at the top of the program (before the For statement) to set the timings for the two Wait values, and use those variables instead of numbers in these statements.
Quit and run the program again. Observe the blinking and the values displayed on the calculator 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 (2563) 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 Disp with the title of the program.
- Add Request and, in quotations marks, add the text Wait?.
- Then add a comma and the variable w.
- This variable will be used in a Wait statement, so 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 speed things up a bit.
Notes: Local i 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 things out.
It’s a good thing that 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.
Complete the First Loop
- Add the rest of the pieces of the For statement to make the value of i increment from 0 to 255. Use the loop variable i and the step variable s.
- Add the Send “SET COLOR statement from the [PRGM] 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.
- Remember to close the quotes and the parentheses.
- 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 just so you can 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 re-use the variable i from the first For loop.
In the image to the right, note that we chose to use the former 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 subtract 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.
Here’s 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.
- Then 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 (like on a guitar or piano). The notes of the musical scale have a special mathematical relationship. There are 12 steps in an octave to get from a note in one octave to the same note in the next 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 principal 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, and then, in the next statement, multiplied it by 21/12.
The calculator 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 Disp, add opening and closing quotation marks, and type the text Music Scale.
- Assign the starting frequency, 261.64 to the variable 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/12This statement takes the current value of f and changes it to the next higher note’s frequency on the scale.
- Store (ctrl-B) and run the program in the Calculator app.
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.
Application Computer MusicTeacher's Notes
You will use the random number generator on the TI-84 Plus CE 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 calculator screen using Disp.
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.
You will 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 frequncy of the note A in the first octave is 55Hz. The range 0 to 59 is used for the 60 notes in the chart. Notice the use of n in 2n/12 to generate the nth note from A1. When n is zero, then the freqency is 55Hz, since 20 is 1.
- 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 Disp statement to show the sensor’s readings.
- Read the BRIGHTNESS sensor
- Introduce the While loop
- Introduce string( ) and concatenation
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 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™. 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- = key.
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:
- While b>1 [use ctrl-= key to select >]
These statements 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 with a hand covering it, the loop and the program terminate.
If you select While…EndWhile from the Control menu, then the EndWhile statement will be in the wrong spot in your code!
It belongs after the Get statement as shown above. You can select it, cut it (ctrl-X), and paste it (ctrl-V) into the right place, or just delete it and type it into the correct place.
The EndWhile of the While loop must also be entered. Below the Get statement, add the EndWhile statement for the end of the While loop.
- Add the Disp statement after the Get statement and before the EndWhile of the loop as shown by selecting menu > I/O > Disp.
- Display the value of the variable b.
- Store the program (ctrl-B), and run the program in the
Calculator app with the TI-Innovator™ Hub attached.
- You should see a sequence of values scrolling down the Calculator app. These values change depending on the light intensity being read by the sensor.
- To terminate 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 lesson, 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 rises.
- READ BRIGHTNESS
- Use a While loop
- Use If...Then...Else...End to turn the light on or off depending on BRIGHTNESS.
Let’s 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 Disp, a set of quotations marks, and the text Auto Light.
- Initialize the variable b by adding the statement 2→b.
- Add a While…EndWhile loop with the condition b>1. (The brightness value is more than ‘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 Disp b to see the reading.
Our 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].
Now for 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.
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.
Get the ‘’ (less than) operator from ctrl-= key
- Finally, turn the LIGHT ON or OFF in the Then and Else blocks as shown.
- Press ctrl-B to store the program.
- 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.
It might help to add a Disp b statement after the Get b statement to display the value of B on the calculator app and add statements in the Then and Else blocks to show whether the light is “ON” or “OFF”.
To stop the loop (and the program), cover the light sensor completely so that the reading falls below 2.
Skill Builder 3 BRIGHTNESS and COLORTeacher's Notes
In this lesson, 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.
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.
- Add a Disp, a double set of quotation marks, and the text BRIGHT to COLOR.
- Set the variable b as shown.
- Add a While…EndWhile loop to read the brightness using Send “READ BRIGHTNESS” and get the brightness variable with Get b.
We will leave the converting part for last.
- 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.
- 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 Hub.
You might want to add some Disp statements to your program to see the values of b and c.
Application Hand 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 and your own moving hand– hence, Hand 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.
- Start a new program, and name it APPLIC3
- Add Disp, add an opening and closing set of quotation marks, and type the text Hand Music! as shown.
- 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 (or two frequencies of your choice).
For musical notes, try a range starting with A1 (55Hz) and going up 50 notes. (You should refer to the activity studied in Unit 2, Skill Builder 3 (we called it prgmSOUND2) 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.
|int(X)→X||gives the largest integer less than X.|
|round(X,0)→X||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