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
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
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