How to control a Dual 7 Segment Display in Arduino + Protues

1.2k views Asked by At

How can I display different numbers in a dual 7 segment with arduino and proteus?

This is my setup:

void setup() {
  pinMode(13,OUTPUT); //a
  pinMode(12,OUTPUT); //b
  pinMode(11,OUTPUT); //c
  pinMode(10,OUTPUT); //d 
  pinMode(9,OUTPUT);  //e
  pinMode(8,OUTPUT);  //f
  pinMode(7,OUTPUT);  //g

  pinMode(6,OUTPUT);  //power 1 (left)
  pinMode(5,OUTPUT);  //power 2 (left)
}

I use this code (in void loop) to display the number 0 in the 7 segment:

  digitalWrite(6, 0);  //power 1 (left)  
  digitalWrite(5, 0);  //power 2 (left)

  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, LOW);

If I simulate this in proteus I got this output:

enter image description here

If I add another number like 8:


  digitalWrite(13, HIGH);
  digitalWrite(12, HIGH);
  digitalWrite(11, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(9, HIGH);
  digitalWrite(8, HIGH);
  digitalWrite(7, HIGH);


this will be the output: enter image description here

The code will just go 0 and 8 on both of the 7segments.

I want it to display 0 on the right and eight on the left but I dont know how to control this dual 7 segment. I want to create a countdown timer, and I have not found any tutorials about it, the tutorials were 2 7 segments in the countdown, not a dual 7 segment display.

Note: I am not using any registers in this project.

1

There are 1 answers

1
Fadi Abu Raid On

The pins 1 and 2 are used to address each one of the seven segments. You need to sink pin 1 to the ground and supplying the value you want to display in the first seven segment then switch to the other by sinking pin 2 to the ground and supplying the value you want to display. This has to happen very fast so human eye won't notice it.

Refer to this circuit

enter image description here

You can use a library that saves you from all of this.

Download the library from here

To install it, open the Arduino IDE, go to Sketch > Include Library > Add .ZIP Library, then select the SevSeg ZIP file that you downloaded.

Then try the following code it should display "80"

#include "SevSeg.h"
SevSeg sevseg; 

void setup(){
  byte numDigits = 2;
  byte digitPins[] = {6, 5};
  byte segmentPins[] = {13, 12, 11, 10, 9, 8, 7, 4};

  bool resistorsOnSegments = true; 
  bool updateWithDelaysIn = true;
  byte hardwareConfig = COMMON_CATHODE; 
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
}

void loop(){
    sevseg.setNumber(80, 1);
    sevseg.refreshDisplay(); 
}