3

What is the difference in using a common anode and common cathode of the 7 Segment in interfacing with the Arduino? How can you change the code if we need to add another 7 Segment display?

How can you change the code to have a counter in backwards (from 0 to 9)?

const int ANODE = 2;   

const int LED1 = 3;   
const int LED2 = 4;   // pin for led 2
const int LED3 = 5;   // pin for led 3
const int LED4 = 6;   // pin for led 4

// now bottom row

const int LED5 = 7;   
const int LED6 = 8;   
const int LED7 = 9;   
const int LED8 = 10;  

int DELAY = 0;        

void setup() {
  pinMode(ANODE, OUTPUT);  // common anode is obviously an output

  pinMode(LED1, OUTPUT);   // led are output for low will be on
  pinMode(LED2, OUTPUT);   // led 2 is output
  pinMode(LED3, OUTPUT);   // led 3 is output
  pinMode(LED4, OUTPUT);   // led 4 is output
  pinMode(LED5, OUTPUT);   // led 5 is output
  pinMode(LED6, OUTPUT);   // led 6 is output
  pinMode(LED7, OUTPUT);   // led 7 is output
  pinMode(LED8, OUTPUT);   // led 8 is output
}

void loop(){

  if (DELAY == 300){
    delay(100000);
  }



  digitalWrite(ANODE, HIGH); 

  digitalWrite(LED1, HIGH);   
  digitalWrite(LED2, HIGH);   
  digitalWrite(LED3, HIGH);   
  digitalWrite(LED4, HIGH); 
  digitalWrite(LED5, HIGH);   
  digitalWrite(LED6, HIGH);   
  digitalWrite(LED7, HIGH);   
  digitalWrite(LED8, HIGH);  

delay(1000);   

  digitalWrite(LED1, LOW);   
  delay(500);                
  digitalWrite(LED1, HIGH);  
  digitalWrite(LED2, LOW);   
  delay(500);                
  digitalWrite(LED2, HIGH);  
  digitalWrite(LED3, LOW);   
  delay(500);                
  digitalWrite(LED3, HIGH);  
  digitalWrite(LED4, LOW);   
  delay(500);                
  digitalWrite(LED4, HIGH);  
  digitalWrite(LED5, LOW);   
  delay(500);                
  digitalWrite(LED5, HIGH);  
  digitalWrite(LED6, LOW);   
  delay(500);                
  digitalWrite(LED6, HIGH);  
  digitalWrite(LED7, LOW);   
  delay(500);                
  digitalWrite(LED7, HIGH);  
  digitalWrite(LED8, LOW);   
  delay(500);                
  digitalWrite(LED8, HIGH);  

  delay(100);                

  DELAY = DELAY + 150;       
}
6

A 7-segment is a packaged set of 8 LEDs (7 number-segments & 1 decimal point). Common anode means that the anode (positive) side of all of the LEDs are electrically connected at one pin, and each LED cathode has its own pin. So turning on any particular segment will involve running a current from this common anode (positive) pin to the particular cathode (negative) pin for the desired segment.

enter image description here

Common cathode means that the cathodes of all of the LEDs are common and connected to a single pin. The anode for each LED has its own pin. So driving one of these means running a current from the particular anode (positive) pin for the desired segment to the common cathode pin.

enter image description here

The way that you are diving the 7-segment involves using a separate pin to drive each segment, so you use 8 pins of the Arduino to drive the display. You will run out of digital pins if you try to add a second 7-segment. There are a couple of ways to address this. One is to add a 7-segment driver, like the CD4511. This limits you to being able to display only numerical digits, but uses only 4 pins of the Arduino per 7-segment.

Another, more versatile way is to add a serial-in to parallel out chip (74HC595, for example) to drive the 7-segment. This requires only two pins from the Arduino (data & clock), and they can be chained to have multiple 7-segments driven from those same 2 pins.

| improve this answer | |
1

Basically you just need to change the HIGH's by LOW's and the LOW's by HIGH's.

| improve this answer | |
0

Spent an hour trying to work it out, seems I have common anode leds. So you have to connect the anode to the 5V (on arduino), The voltages are then reversed, so use 255-v instead of v.

I think common cathode will be easier to understand and program for.

| improve this answer | |
-1

You can easily test this in 123D Circuits, check this out: https://123d.circuits.io/circuits/1019227-7-segment-circuit

Click start simulation and then click on the buttons to light up the corresponding segment.

enter image description here

| improve this answer | |
  • I'm not convinced this addresses the question at all. – CharlieHanson Oct 17 '15 at 1:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.