Dec 16

Sketch 8: Controlling a Seven Segment Display

You will be writing a program to control a seven segment display. You can refer to Lab 8 so that you know what pins the segments on the display are connected to. That way, you will turn on the correct LED's in the seven segment display when you try to display a number.

Again, copy below the /*************/ into the arduino programming environment.


This program will tell the arduino how to display numbers on a seven
segment display. It goes with the laser tag course.
This code only comes with comments. It is intended to help the
reader understand what they need to tell the arduino to do
(Aka, what code to write)
Remember to add comments!

// Variables (nicknames for pins)
We will need a variable for each of the pins that we connect to the
seven segment display so that we can turn that pin on or off
depending on what number we want to display.
All of our variables will be integers, meaning they will start with
int (variable name) = (pin number);
with the stuff in () replaced with the variable name and pin number.

void setup() {
Now we need to tell the arduino if the pins that we are using are
inputs or outputs. We will be sending a signal out to light up
each of the pins of the seven segment display. You use the
pinMode() function to set whether a pin is an input or output.
pinMode() accepts two inputs, the pin number and whether it is an
for example: pinMode(pin_3, OUTPUT);
the command above would set pin 3 to be an output (assuming pin_3 is
a variable that you set to 3)

//now for the main loop da loop
void loop() {
we've told our arduino what pins we are using and whether those
pins are inputs or outputs. Now we need to tell it what to display.
Just for fun, we want to have the display switch between two numbers,
0 and 1. You will should program the arduino to turn off all of the
segments (maybe by writing a function to do that, since you will need
to do that twice...), and then turn on the segments that correstpond
to either 0 or 1. You can have it waid for 1 second between the digits.
Be sure to add comments to your code so that you know what it is doing.


Now we want to write a function that turns off all of the digits. Use
this function in the loop above so that you don't have to copy and
paste it every time you want to turn the segments off before
turning them on to display a new digit.

//Tlia. Xlex aew e psx sj gshmrk. Asyphr'x mx fi kviex mj csy hmhr'x lezi xs hs epp xlex asvo xs hmwtpec e ryqfiv?


Dec 15

Lab 8: 7-Segment LED Wiring

You are going to need to take the piezo speaker off of your breadboard in order to complete this lab. We are going to put the seven segment LED on the bottom of the breadboard and connect it to pins 2-9 on the arduino. You will also have to take the infrared sensor out of pin 9. Here is the wiring diagram for the seven segment LED (with all other pieces taken out to make it easier to focus on how to wire the seven segment display, which is sometimes written 7-segment display).


Once we have the 7-segment display wired to the arduino, we are going to need to program the arduino to turn on each of the segments in the 7-segment display in order to display the number that we want it to. There is one more thing that will be helpful to program the 7-segment LED, and that is which segments are controlled by which arduino pins.

Below is a schematic drawing of the 7-segment LED. Each of the triangles with a line and two arrows represents an LED. The direction of the triangle shows which way the electricity can flow.

It's coding time! To sketch 8.

Note: If you want more of a challenge, don't look at the schematic above to program the seven segment LED. Determine what pins control which segments by trial and error.

Dec 15

Lesson 8: 7-segment LED's

One of the current problems with the laser tag unit is that you don't know how much health you have left. Wouldn't it be great if you could have the arduino tell you how much health you had left? There are a few ways to do this. The one we are going to go over is a seven segment LED. A seven segment LED is a group of LED's that are arranged to look like a figure 8. By lighting up different LED's, you can make numbers 0-9 (and a few other symbols, if you want).

There are seven LED's that light up each straight part of the of the figure 8 in the display (that's why it's called a 7-segment LED. There are 7 segments that light up.). If we had to wire every LED like the one that we put on our board, we would have to put 14 wires (one for the + and one for the - side of every LED) to wire our 7-segment LED. That's a lot of wires. Instead of doing that, the people that manufactured the 7-segment LED that we will be using wired all of the grounds (negative) for the LED's together to one pin. That way, you only need to connect that 1 wire to ground to have every single segment on the LED connect to ground. Nice of them, huh?

A seven segment LED looks like this:

7-seg LED picture

What we need to do is connect each one of the pins that controls the lights in the seven segment display to our arduino. After that, we can program the arduino to turn on whichever segments we want in order to display a certain number. So, let's get wiring (on to Lab 8)!