Phase1: Basic Counter
When you need to teach your child the numbers you start
to teach them numbers in ascending order. “Hey .. first number is 1.. 1 means
one thing.. When I have 1 and another 1 that means we have two things.. Then 2
is a number means 1+1 .. etc” You then will ask him/her to counting up the
numbers: “Tell me the numbers from 0 to 9”.. and the child start to be like a
counter ( 0,1,2,3,4,5,6,7,8,9). Our first robot in this series, is this
child.. We make a child with 7 figures (as bulb) to say the numbers..
The 7-segments Display
Robot’s fingers,
they aren't like ours it’s more simple.. It’s a collection of LEDs which make
the basic element in most of display monitors in our digital life.
We see the 7
segment every day! We see and use it everywhere in our digital life and get benefits
from it, without the 7 segment we think the life will be a little bit horrible!
The 7-segments this is our story hero, the figures, the basic element of display monitors in
calculators digital alarm clock, gas station & price changer signs, stock
market, on microwave oven display screens, عداد اجرة التاكسي... etc.
This element to be used correctly we have to understand its physical construction, we have to understand how we can give a power to it, and how to control the lighting of each segment?
This element to be used correctly we have to understand its physical construction, we have to understand how we can give a power to it, and how to control the lighting of each segment?
Anatomy of 7-Segment Display
When you are
going to explore the component, you will figure that there are 10 pins in the 7
segment; each PIN wired one segment! 10 PINs and you said 7 Segments? There is
a decimal point, the small dot on the bottom right, and then now we have
another pin for dot, 8 PINs know now. There are still two PINs? For what these
PINs for, you will know soon.
First, we need to identify PIN1 in order to probably
assign a power (+) and ground (-) to the pins. This information is found on the
technical specifications sheet also known as the "data sheet”. Second,
every PIN lights up a segment; we can give each segment a letter:
PIN1 -> E , PIN2 -> D , PIN4 -> C , PIN5 -> DP
"Decimal Point" , PIN6 -> B, PIN7 -> A
PIN1
|
E
|
PIN2
|
D
|
PIN4
|
C
|
PIN5
|
DP
|
PIN6
|
B
|
PIN7
|
A
|
For PIN3, PIN8,
they will be connected to the ground if you work with "7 segment Common
Anode" but if you work with "7 segment Common Cathode “then you have
to connect the these PINs to the power(5V).. What’s the common cathode and
anode stands for? Follow this tutorial for more information
Now, we know the
parts of the 7 segment and we are ready to learn how to use it and light them up!
Build the Robot
Hardware Components:
·
Arduino chip ( we use Arduino Uno)
·
Breadboard
·
1x 7segement display
Steps to make robot ready:
(1) Put the 7segment in the bread board
(2)Start to connect Arduino Digital PINs with 7-segement PINs, in the following manner:
PIN in the
7segmant
|
Digital Pin in the ARDUINO
|
1
|
2
|
2
|
3
|
3
|
5V *
|
4
|
4
|
5
|
-
|
6
|
5
|
7
|
6
|
8
|
5V *
|
9
|
7
|
10
|
8
|
* Because we use common cathode
7-segment display
Teach the Robot
We are ready now to teach
the robot(write and upload the sketch to the Arduino). Well, first we want to
identify our problem:
We want to display the
numbers starting from 0 to 9 in the 7-segement display.
To start search of where
we can start write the code, we want fist to identify the PINs we will turn it
on and off (the PINs of Arduino). By the way we used in connecting the Arduino
to 7-segement, we can say:
int segementPINS[]={2,3,4,6,7,8,9}; // 1 2
4 6 7 9 10
// E D C
B A F G
|
This array say that the PIN number 2 in Arduino,
connected to the E segment, so when we send a high signal to this pin, E
segment will turn one(note: that we are using common cathode, that the segment
won’t turn on except we send a low signal..make sure for your 7-segment
component). The same is for the other
elements of the array.
To display the number on 7 segments, we have to say for
each number which segment will turn on/off. For instance to display the number
0, all segments should be turned on except segment G. so we can draw a truth
table for 7-segments with numbers
E
|
D
|
C
|
B
|
A
|
F
|
G
|
|
0
|
1
|
1
|
1
|
1
|
1
|
1
|
0
|
1
|
0
|
0
|
1
|
1
|
0
|
0
|
0
|
2
|
1
|
1
|
0
|
1
|
1
|
0
|
1
|
3
|
0
|
1
|
1
|
1
|
1
|
0
|
1
|
4
|
0
|
0
|
1
|
1
|
0
|
1
|
1
|
5
|
0
|
1
|
1
|
0
|
1
|
1
|
1
|
6
|
1
|
1
|
1
|
0
|
1
|
1
|
1
|
7
|
0
|
0
|
1
|
1
|
1
|
0
|
0
|
8
|
1
|
1
|
1
|
1
|
1
|
1
|
1
|
9
|
0
|
1
|
1
|
1
|
1
|
1
|
1
|
We store this table in 2D array:
int nums[10][7]={{1,1,1,1,1,1,0}, /* 0 */
{0,0,1,1,0,0,0}, /* 1 */
{1,1,0,1,1,0,1}, /* 2 */
{0,1,1,1,1,0,1}, /* 3 */
{0,0,1,1,0,1,1}, /* 4 */
{0,1,1,0,1,1,1}, /* 5 */
{1,1,1,0,1,1,1}, /* 6 */
{0,0,1,1,1,0,0}, /* 7 */
{1,1,1,1,1,1,1}, /* 8 */
{0,1,1,1,1,1,1} /* 9 */
};
|
To turn the segment on
we simply make a function “void
lightUpSegement(int num)” that take the desired number to display num.
this num is the first index of nums array(i.e. the row number). If we want to
display number 3 ( num=3) then we want row=3 ({0,1,1,1,1,0,1}) we have this row, access each element by a for
loop if the element equals 1 then we have to turn the segment on:
digitalWrite(segementPINS[j],LOW); // turn
on : common cathode
|
Else (equals to 0)
digitalWrite(segementPINS[j],HIGH);
// turn off : common cathode
|
In the loop function, make a for loop that calls lightUpSegement function for each
number between 0 and 9, and of course set some delay between each display
for(int j = 0 ;j <10 ; j++ )
{
lightUpSegement(j);
delay(2000);
}
|
Don’t forget to state in the setup function that segementPINS is used as output PINs
void setup(){
for(int i = 0 ; i<7 ; i++){
pinMode(segementPINS[i], OUTPUT);
}
}
|
And we are done! Verify, upload.. and your robot start to
counting the numbers : )




No comments:
Post a Comment