To Do

Assignment Seven – Develop Your Project!

Now it’s time to develop your project and get it up and running on your breadboard.

At the moment, there are two kinds of projects in development; a Traffic Light Simulator, and an Intruder Detector. Both of these projects rely on having the Teensy continuously send out pulses of infrared light and then detect whether or not they have been received – i.e, the Teensy must be able to determine whether or not some object is blocking the beam of light pulses.

As this goes a little beyond the topics we’ve been able to cover so far, I have put together a Project_Framework sketch that handles the light beam stuff. You should be able to start with this framework and figure out how and where to add the additional LED outputs you may need in order to create your particular project.

Just click on this Project_Framework link – you can cut and paste, or right-click and “download as” and save it as a sketch to feed your Teensy. Be sure to look at the pin number assignments so that you will know how to wire things up.

Assignment Six – Choose Your Project!

Well, the time has come to settle on a project! Between now and our next class, be sure to look over the list of projects here on the lab page and be ready to tell me which one appeals to you most! You may also make up your own project idea, but I will have to approve it and determine whether or not it is something you will be able to complete before classes are over!

Remember, you will have to figure out how to wire this up and how to program it. I will, of course, gladly help you do that! :)

Assignment Five – Review Control Structures

Learning and understanding how the Arduino programming control structures work is very important, and so here are some Arduino Sketches for you to experiment with! Each one focuses on one of the control structure types.

Try them all, try changing inputs and make an effort to understand how they work!

Assignment Four – More Control Structures

Last Friday we worked with an Arduino sketch called ControlFun2. The main purpose of that program is to help you understand how these control structures work:

  • if <- Test a condition and perform an action if the result is TRUE
  • if…else <- Test a condition and perform one action or another if the result is TRUE
  • for <- Perform an action for a counted number of times
  • switch case <- Select an action based on the value of case
  • while <- Perform an action as long as a condition is TRUE
  • do… while <- Perform an action at least once and then for as long as a condition is TRUE
  • break <- Exit a while, do, for, or switch statement

These are the most important control structures, and it is very important that you really understand what they do so that you can use them in your own projects! :) You will understand them better as you use and experiment with them in the program, but you can also click on their links above to read the Arduino reference material about them in case you have forgotten exactly what they do. :)

Here is an improved version of the control program we used in our last class:
ControlFun3 <- Click to open

Note that I’ve added lots of comments! Remember, comments are anything after a ‘//‘ on any line. Comments are completely ignored by Teensy 3.0, but are important to help you remember and understand what the program is doing! :)

The bread board is set up with four LEDs, wired like the example in Assignment One, one each on Digital I/O pins 0 through 3 of your Teensy 3.0. There is also one input wired like this:

switch-pullup

The resistor, in this use called a “pull-up,” is there to “hold” the input in a HIGH state until and unless you use a wire or switch to pull the level down to GND or LOW.

Please open up ControlFun3 and copy it to your Arduino sketch book, and then try it out! Depending on how you have your LEDs wired in your breadboard, you may need to change the pin numbers in the program, or else change your bread board to match the program!

Things to Note and Do: There are examples of each of the listed control structures in this program! Be sure to identify them!

You may wish to print out this PDF copy of ControlFun3 <- Click to open – and use a highlighter as you think about how the program works! :)

Start by finding the loop() function, which is the last one in the program… void loop() … It is in the middle of page three of the PDF printout.

Now, find the statement int limit = 5; and change the ‘5‘ to other values in order to see how the program behavior changes!

Experiment with different limits, particularly 1, 2, 3, 4, and 5… Depending on which of those limits you set, a different “case” will be executed! If you set a lower or higher limit, then the “default” case will be executed.

Of course, don’t forget that after each change you make in the program, you must re-compile and re-load the sketch into your Teensy 3.0! :)

Then, for each of the different cases, try changing the number of counts that the for loop executes. For example, find the for loop in case 1:for(count = 0; count < 7; count++) – and change the ‘7‘ to some other value – how about 30? – and if your limit is set to one, then this case will run 30 times.

Finally, if you are up for a real challenge this week!, try adding four more LEDs to your breadboard, and see if you can figure out how to incorporate the extra LEDs into the program function! :)

Please feel free to contact me with any questions you may have, and I’ll see you on Friday, God willing!

Assignment Three – Control Structures

I hope you had fun with the Star Trek phaser sound program last week! :)

Before you come to class on Friday, please see if you can make the sound go opposite of whatever way it is now going… and then have two copies of the phaser program to show me – “phaser-up” and “phaser-down” – which means you need to use a “save-as” on the copy you modify!

Also, we’ve started to use some “control structures” which are simply program tools, sort of like Lego building blocks!, that help us tell the micro controller exactly what to do and when to do it! You may remember that when we wanted to add a trigger to our phaser, we used an “if statement.” The if statement is one kind of several available control structures. We instructed the micro to make the phaser sound only if the trigger input was present.

Also before class this week; Please go to and look over the Arduino Reference Page. You can also find a copy of this page conveniently linked from any open Arduino sketch window – like the phaser program, or your blinking programs – Just select Help->Reference. The web link is: http://arduino.cc/en/Reference/HomePage

On the reference page, before class, please do this: See how many of the entries that you see there you have already seen and used in a program! I can see them “popping out” at me all over that page! When you spot any item that you think you know about, see if you can tell what it is or what it means – and then, check your knowledge by clicking on it and reading more about it! :) I see, for instance, digitalRead() and digitalWrite() and pinMode() in the Digital I/O category, and HIGH/LOW and INPUT/OUTPUT in the Constants category. What else looks familiar to you? :) Hint: Open one of your Arduino sketches and have a look! 😉

For example, we used the if statement to check our triggerPin input pin… When we did that, we used a Comparison Operator known as “equal to” with the symbol of a double equal sign (==) and so, read about both the if statement in the Control Structures section and the == (equal to) Comparison Operator.

We will talk about more Control Structures this Friday, God willing! :)  See you then! :)

Assignment Two – A Sound-Making Program

In our next class, we will use Teensy 3.0 board to create some cool sound effects. Your assignment in preparation for that is to simply copy this program into your Arduino programming environment and save it with the name of “audio.” To do this, open the Arduino program, select “File->New” and then either copy and paste or type the following program in.

This program will generate a “square wave” output on Teensy pin 11. We will feed that to a sound generating device, like a speaker or headphone. I will bring along the parts you need to make the final connection; but be thinking about how we can change the frequency of the sound output!

The program is very short and simple – it turns a single bit on and off rapidly! See if you can be ready to explain to the class what each part of the program does! :)

//
// Computer Sound Maker
//
#define S_DELAY 3

const int speakerOut = 11; // Speaker output pin
const int ledPin = 13; // Teensy 3.0 LED output

void setup() {
pinMode(speakerOut, OUTPUT);
}

void loop()
{
digitalWrite(speakerOut, HIGH);
delay(S_DELAY);
digitalWrite(speakerOut, LOW);
delay(S_DELAY);
}

Assignment One – Blink 2 LEDs

In class, we got our Teensy 3.0 boards connected to our laptop computers with a USB cable and the Arduino software. We saw that we could load a program and make the LED on the Teensy board blink. Some of us even got as far as making two LEDs blink!

Your assignment is to come to our next class with a working, blinking 2-LED bread board and program. Here is all the information you should need to do that! :)

First of all, this is a hybrid schematic of the circuit you will need.teensy-2LEDYou already have one orange LED connected to Teensy Pin13 on the Teensy board itself, so all you need to add is a circuit with an LED, a resistor (to limit the current flowing through the LED!), and a couple of wires to connect those components between Teensy Pin 13 and the GROUND pin (Pin 1). This is one way this could look on your breadboard:bb-2LED-l

Note that the 200 ohm (color code RED,BLACK,BLACK,BLACK – check the lab page for a chart) is connected between rows 40 and 35; the Red LED has its short lead in row 35 connected to the resistor, and its long lead connected to a wire that in turn connects to pin 12 on the Teensy 3.0 board. The other end of the resistor is connected by a wire to Pin 1 of the Teensy, which is ground or GND. You can find a RED LED and some 200 ohm resistors in the small plastic bag in your lab kit marked RED.

WARNING!: Be sure that you have the resistor in this circuit and that you do not connect the LED directly to the Teensy pin. Without the resistor in place, too much current will flow through the circuit and possibly burn out the LED or the Teensy or both!

Now you need to tell the Teensy to turn on your newly connected LED. Open your Arduino program and then use the File menu to get the Blink software:

File->Examples->Teensy->Tutorial1->Blink

Be sure to change the “const int ledPin = 11;” to be “const int ledPin = 13;” because Teensy 3.0 has its LED connected to Pin 13. Use the “Upload” button (Arrow in Circle) to compile and load your code. You should see the LED on your Teensy blink.

Now figure out how to change the program so that your newly added LED also blinks!

HINT: You can do this by copying some lines in the existing program and changing the name of the LED variable. We did this in class, so think about it, and Good Luck! If you have difficulty, we’ll go through this again during our next class.

Install Teensy 3.0 Software On Your PC

Here is a link to the Teensy 3.0 Development page: http://www.pjrc.com/teensy/index.html

This link has some more specific installation instructions on it: http://www.pjrc.com/teensy/td_download.html

Please contact me if you have any trouble installing this! And don’t worry too much; I’ll be glad to help you, particularly if you can bring your laptop to class; if not, I will arrange to visit your home and help with the installation. This is an important step, because learning to use a micro controller will require having these tools in place! :)