3 Digit 7 segment display + Arudino - Multiplexing , Counter

Hi Guys,
My partner and I are trying to use arduino and this 3 digit 7 segment display -

To make a simple counter with a 3 digit range of 0 to 999, so when a SPDT switch is set HIGH, the numbers rise and when the switch is LOW. The numbers decrese. Very simple...

For the life us we can't seem to find any tutorals which feature this and most of them seem to feature single digits or 4 digit segment displays...

We're also having trouble understand the schematic of our particular display and specifially what are the pin out arrangement to an arduino nano would be...

Amongst the many videos and tuts this seems to be the most simple as it using no shift registers and connects directly to the arduino, but we're a struggling with figureing out the pin arrangment. Can any one suggest the easiest way to accomplish our goal with this project. Thanks so much!

By amazing coincidence I bought the 2-digit version of that yesterday.

Use the SevSeg library and set numDigits to 3 for yours. You obviously have a variable holding your incrementing number: put that variable in the setNumber.

Heed what they say about having to use non-blocking code else their refresh doesn't work. So if you want each value to stop on the display for say 1/2 second, you'll need a BlinkWithOutDelay approach.

Here's one way to wire them up.
Write your code to turn on One of the common anode pins and One of the cathode pins at a time.
Cycle thru all of the pairs like that, turning on each LED one at a time for 1mS, until you've gone thru all of them,
then go back and do it again.
Using blink without delay, you can do other stuff while the 1mS is passing.

I think that's basically what the SevSeg library does CrossRoads.

As a matter of interest though, the default config for that library is to have the resistor on the common only, ie one per digit not one per segment. Presumably only one segment is ever on, so only one resistor is required and the speed of refresh gives the illusion of "solid on".

That would work also.
Too used to drawing it up with a shift register and turning on each digit one by one.

Thanks for the responces, so last night we had some progress and have got it wired up correctly.

We can set any number to appear on the display using the code below.

but now to ask the question again in respects of the only code/method we got it working with -

How can we create a looping counter the lets us make
a count up/count down to a thousand and down to zero. ?

Also we have figured out that it is NOT a spdt switch we need but 2 independent momentary switches that when held down will signal the countdown/ups.

/*
Showing number 0-9 on a Common Anode 7-segment LED display
Displays the numbers 0-9 on the display, with one second inbetween.
  A
 ---
F |   | B
| G |
 ---
E |   | C
|   |
 ---
  D
This example code is in the public domain.
*/

// Pin 2-8 is connected to the 7 segments of the display.

int pinA = 2;
int pinB = 3;
int pinC = 4;
int pinD = 5;
int pinE = 6;
int pinF = 7;
int pinG = 8;
int D1 = 13;
int D2 = 9;
int D3 = 10;


// the setup routine runs once when you press reset:
void setup() {                
// initialize the digital pins as outputs.
pinMode(pinA, OUTPUT);     
pinMode(pinB, OUTPUT);     
pinMode(pinC, OUTPUT);     
pinMode(pinD, OUTPUT);     
pinMode(pinE, OUTPUT);     
pinMode(pinF, OUTPUT);     
pinMode(pinG, OUTPUT);   
pinMode(D1, OUTPUT);  
pinMode(D2, OUTPUT);  
pinMode(D3, OUTPUT);  

}

// the loop routine runs over and over again forever:
void loop() {
digitalWrite(D1, HIGH);
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);

//First segments
digitalWrite(pinA, LOW);   
digitalWrite(pinB, LOW);   
digitalWrite(pinC, HIGH);   
digitalWrite(pinD, LOW);   
digitalWrite(pinE, LOW);   
digitalWrite(pinF, HIGH);   
digitalWrite(pinG, LOW);     
delay(1);

//Second segments
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
digitalWrite(D3, LOW);



digitalWrite(pinA, HIGH);   
digitalWrite(pinB, LOW);   
digitalWrite(pinC, LOW);   
digitalWrite(pinD, HIGH);   
digitalWrite(pinE, HIGH);   
digitalWrite(pinF, HIGH);   
digitalWrite(pinG, HIGH);     
delay(1);

//Third segments
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
digitalWrite(D3, HIGH);

digitalWrite(pinA, LOW);   
digitalWrite(pinB, LOW);   
digitalWrite(pinC, LOW);   
digitalWrite(pinD, LOW);   
digitalWrite(pinE, HIGH);   
digitalWrite(pinF, HIGH);   
digitalWrite(pinG, LOW); 

delay(1);               // wait for a second

}

OK, tidied that up except for the "Auto Format" in the Tools menu to properly present the code.

Your life will be infinitely easier if you use the library as I suggested yesterday.

This code is what I put together when I was playing around; it simply uses loop() to increment a counter from 00 to 99 in my 2-digit display.

/*
  JimboZA April 2016
  uses sevseg library
  the sevseg refresh means NO blocking code may be used, hence elapsedMillis
  change the .h to reflect segment resistors
*/

#include <SevSeg.h>
#include <elapsedMillis.h> //bwod in a box

SevSeg sevseg; //Instantiate a seven segment controller obj
elapsedMillis timeElapsed;
unsigned int interval = 1000; //how many ms each value displays

byte theNum = 0; // what I want to display

void setup() {

  Serial.begin(9600);
  // put your setup code here, to run once:
  byte numDigits = 2;
  byte digitPins[] = {2, 3};
  byte segmentPins[] = {4, 5, 6, 7, 8, 9, 10, 11}; //Segments: A,B,C,D,E,F,G,Period

  sevseg.begin(COMMON_CATHODE, numDigits, digitPins, segmentPins);
  sevseg.setBrightness(100);

  // Jim has resistors on the segments, so edited sevseg.h thus:
  // If you use current-limiting resistors on your segment pins instead of the
  // digit pins, then change the '0' in the line below to a '1'
  //#define RESISTORS_ON_SEGMENTS 1

  Serial.println("setup complete");

}

void loop() {
  // put your main code here, to run repeatedly:

  sevseg.setNumber(theNum, 0);

  sevseg.refreshDisplay(); //must not block this

  //delay(500); // this screws the refresh up so bwod required:

  if (timeElapsed > interval)
  {
    theNum++;
    if (theNum == 100) theNum = 0;
    timeElapsed = 0;
  }
}//loop

We have been able to successfully used Seven-seg library. We have modified the code to fit our 3digit system by modifying it for an anode based display and also changing the anode pins.

For some reason though the 'A' -LED on the first digit is always lit. So this is probably the next issue to tackle before we focus on the count down/up loops.

and currently the code as it stands is counting up but how do we adapt the code so it will react to the respective momentary button switch and count-down. Many thanks

Here is the code below:

/* SevSeg Counter Example
 
 Copyright 2014 Dean Reading
 
 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at 
 http://www.apache.org/licenses/LICENSE-2.0
 
 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 
 
 This example demonstrates a very simple use of the SevSeg library with a 4
 digit display. It displays a counter that counts up, showing deci-seconds.
 */

#include "SevSeg.h"

SevSeg sevseg; //Instantiate a seven segment controller object

void setup() {
  byte numDigits = 3;   
  byte digitPins[] = {13, 9, 10};
  byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8};//Segments: A,B,C,D,E,F,G,

  sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins);
  sevseg.setBrightness(90);
}

void loop() {
  static unsigned long timer = millis();
  static int deciSeconds = 0;
  
  if (millis() >= timer) {
    deciSeconds++; // 100 milliSeconds is equal to 1 deciSecond
    timer += 100; 
    if (deciSeconds == 100) { // Reset to 0 after counting for 1000 seconds.
      deciSeconds=0;
    }
    sevseg.setNumber(deciSeconds, 1);
  }

  sevseg.refreshDisplay(); // Must run repeatedly
}

/// END ///
1 Like

here's a video on a progess.

https://drive.google.com/file/d/0B77VPq7qVU8ncjMzRE93VUhCVzA/view

Although short the when the numbers hit 99 the reset to 0. We are trying to reach upto 999 the max for this display and also there is weird bug with the first digit having one of the leds always on.

Thanks

Bump...Anyone please? thanks

Sorry, am not familiar with that library.