7 segment display code

How to interface 7 segment display with Arduino code.?

Make font mapping array:

byte fontArray [] = {
0b00111111, // 0  will connect to DP-g-f-e-d-c-b-a
0b00000110, // 1
0b01011011, // 2
// etc
};
[code]
Send the bits out to pins
[code]
if ((numberToSend[fontArray] & 0b00000001) == 0){
digitalWrite (segmentApin, LOW);
}
else {digitalWrite (segmentApin, HIGH);
}
if ((numberToSend[fontArray] & 0b00000010) == 0){
digitalWrite (segmentBpin, LOW);
}
else {digitalWrite (segmentBpin, HIGH);
}
if ((numberToSend[fontArray] & 0b00000100) == 0){
digitalWrite (segmentCpin, LOW);
}
else {digitalWrite (segmentCpin, HIGH);
}
if ((numberToSend[fontArray] & 0b00001000) == 0){
digitalWrite (segmentDpin, LOW);
}
else {digitalWrite (segmentDpin, HIGH);
}
if ((numberToSend[fontArray] & 0b00010000) == 0){
digitalWrite (segmentEpin, LOW);
}
else {digitalWrite (segmentEpin, HIGH);
}
if ((numberToSend[fontArray] & 0b00100000) == 0){
digitalWrite (segmentFpin, LOW);
}
else {digitalWrite (segmentFpin, HIGH);
}
if ((numberToSend[fontArray] & 0b01000000) == 0){
digitalWrite (segmentGpin, LOW);
}
else {digitalWrite (segmentGpin, HIGH);
}

There's a lot of redundancy there, yes? So a for:loop and an array or two could be used to clean it up some, while retaining the same functionality. Get your hardware working first, then come back with your sketch and we can shorten it.

byte fontMask [] = { 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,}; // replaces
byte pinMap [] = (2,3,4,5,6,7,8,9,}; // segments a,b,c,d,e,f,g,DP
for (x=0; x<8; x=x+1){
if ((numberToSend[fontArray] & fontMask[x]) == 0){
digitalWrite (pinMap[x], LOW);
}
else {digitalWrite (pinMap[x], HIGH);
}

[/code]

[/code]

You have to find out your display segments (a ... g) by sending 0B1000000, 1B01000000, ... 1B00000001 to your display and put these values in the array (zeichen).

//  Shift Register with TPIC6B595

int pinLatch =8;
int pinClock =9;
int pinData = 10;

// define characters (zeichen) 0 thru 9 (A0 of 595 chip is not used in my case)


byte zeichen[] =  {0B10111110, 0B10100000, 0B11011010, 0B11110010, 0B11100100,
                   0B01110110, 0B01111100, 0B10100010, 0B11111110, 0B11100110};

void setup() {
  pinMode(pinLatch,OUTPUT);
  pinMode(pinClock,OUTPUT);  
  pinMode(pinData,OUTPUT);
}

void loop() {
  for (int i=0; i<=9; i++)  {
    digitalWrite(pinLatch,0);      // LOW during tdata transfer
    shiftOut(pinData,pinClock,MSBFIRST,zeichen[i]);
    digitalWrite(pinLatch,1);      // take over data with a LOW to HIGH signal
    delay(500);
  }
}

By the way: "zeichen" is german and means sign/character.

If the display has multiple digits (4 is quite common) and the corresponding segments are wired together, you will also have to use a multiplexing technique. There are other solutions using driver chips, especially if your display device(s) are common cathode types.

You could use the SevSeg library.

I would imagine wiring the segments together and multiplexing them would be a good idea, even if they weren't already. The ledcontrol library and MAX7221 is worth a look.

http://playground.arduino.cc/Main/MAX72XXHardware

Shift registers do NOT ONLY have a Serial IN port, they have a Serial OUT port as well.
Just daisy-chain them (connect them).

All the signals you need is SI (serial in), Latch and Clock at your Arduino - 3 pins - that is it.

The names of the pins are varying widely, however, it is alwas the same scheme.

Three control pins for as many segment you want.

The shiftout routine of the Arduino IDE is working very well.

Forget about multiplexing, it makes things more complicated.

You may also use chips that can control 4 or more 7-segment displays.

What about using an LCD display?
The LCD library from, the Arduino IDE is working very well.

For more than 2 digits I use a 4-line 20 character LCD display ... gives you up to 80 characters.

Nevertheless, LED 7-segment displays look much nicer.