Step 6Project 2: '2 Wire' 7 Segment display controller
bit 1 = pin 3
bit 2 = pin 4
bit 3 = pin 5
bit 4 = pin 6
bit 5 = pin 10
bit 6 = pin 11
bit 7 = pin 12
bit 8 = pin 13 (if you want to use the decimal point)
And the cathode of the display through the 330ohm resistor and to power supply ground
now open the seven_seg_demo.pde in the arduino IDE
First you see where we define the data and clock pins
#define data 2
#define clock 3
Next we set all of the charater patterns in binary, this is pretty easy, look at the drawing below, if you need the middle segment type in a one, next do you need the top segment, if so type in another one, keep doing this until you cover all 8 segments, notice my rightmost bit (bit 8) is always 0, thats becuase i never turn on the decimal point.
byte zero = B01111110;
byte one = B00000110;
byte two = B11011010;
byte three = B11010110;
byte four = B10100110;
byte five = B11110100;
byte six = B11111100;
byte seven = B01000110;
byte eight = B11111110;
byte nine = B11110110;
next in void setup we set our data and clock pins to outputs
void setup()
{
pinMode(clock, OUTPUT); // make the clock pin an output
pinMode(data , OUTPUT); // make the data pin an output3
}
then in void loop we use shiftOut to display each pattern (number) wait 1/2 a second and display the next, 0 to 9, since its being done in the void loop function it will count 0-9 and repeat forever.
void loop()
{
shiftOut(data, clock, LSBFIRST, zero);
delay(500);
shiftOut(data, clock, LSBFIRST, one);
delay(500);
shiftOut(data, clock, LSBFIRST, two);
delay(500);
shiftOut(data, clock, LSBFIRST, three);
delay(500);
shiftOut(data, clock, LSBFIRST, four);
delay(500);
shiftOut(data, clock, LSBFIRST, five);
delay(500);
shiftOut(data, clock, LSBFIRST, six);
delay(500);
shiftOut(data, clock, LSBFIRST, seven);
delay(500);
shiftOut(data, clock, LSBFIRST, eight);
delay(500);
shiftOut(data, clock, LSBFIRST, nine);
delay(500);
}
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|

















































