I’m using a 4 digit seven segment display from an alarm clock that only has 9 pins

I tried looking it up and found nothing useful.

I have a solution that I will better document later today. I am using pins on the Arduino to switch from high to low and they seem to function fine as power and ground respectively. I have gone through and labeled each pin configuration for each segment.

1 Like


This is the pin layout for each segment I’ve worked out.


Because I am only using these specific segments they are the only ones I’ve labeled

  int oneA = 22;
  int twoA = 23;
  int threeA = 24;
  int fourA = 25;
  int fiveA = 26;
  int sixA = 27;
  int sevenA = 28;
  int oneB = 29;
  int twoB = 30;
  int threeB = 31;
  int fourB = 32;
  int fiveB= 33;
  int sixB= 34;
  int sevenB = 35;
  int clock = 60;
int pin1 = yes;
int pin2 =no;
void setup() {

  // put your setup code here, to run once:
digitalWrite(oneA,LOW);
digitalWrite(twoA,LOW);
digitalWrite(threeA,LOW);
digitalWrite(fourA,LOW);
digitalWrite(fiveA,LOW);
digitalWrite(sixA,LOW);
digitalWrite(sevenA,LOW);
digitalWrite(oneB,LOW);
digitalWrite(twoB,LOW);
digitalWrite(threeB,LOW);
digitalWrite(fourB,LOW);
digitalWrite(fiveB,LOW);
digitalWrite(sixB,LOW);
digitalWrite(sevenB,LOW);



}

void loop() {
  while( clock == 60){
 
      }

}



void one(){

pin1=sevenA;
pin2=threeB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void two(){

pin1=twoA;
pin2=oneB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}
void three(){

pin1=twoA;
pin2= fourB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void four(){

pin1=oneA;
pin2=twoB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void five(){

pin1=oneA;
pin2=sevenB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}
void six(){

pin1=fourA;
pin2=twoB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}
void seven(){

pin1=sevenA;
pin2=oneB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}


void eight(){

pin1=threeA;
pin2=oneB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void nine(){

pin1=twoA;
pin2=threeB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void ten(){

pin1=oneA;
pin2=threeB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void eleven(){

pin1=twoA;
pin2=fiveB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void twelve(){

pin1=threeA;
pin2=fourB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}
void thirteen(){

pin1=sixA;
pin2=threeB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void fourteen(){

pin1=fourA;
pin2=threeB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void fifteen(){

pin1=threeA;
pin2=sixB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void sixteen(){

pin1=oneA;
pin2=sixB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void seventeen(){

pin1=sevenA;
pin2=twoB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void eighteen(){

pin1=sixA;
pin2=twoB;

  pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
digitalWrite(pin2,HIGH);
delay(1);
digitalWrite(pin2,LOW);
pinMode(pin1,INPUT);
pinMode(pin2,INPUT);
delay(1);
}

void colon(){
three();
four();
}

void 3one(){
one();
two();
}


void 2zero(){
five();
six();
seven();
nine();
ten();
eleven();
}

void 2one(){
seven();
ten();
}

void 2two(){
five();
seven();
eight();
nine();
eleven();
}

void 2three(){
five();
seven();
eight();
ten();
eleven();
}

void 2four(){ 
six();
eight();
seven();
ten();
}

void 2five(){
five();
six();
eight();
ten();
eleven();
}

void 1zero(){
twelve();
thirteen();
fourteen();
sixteen();
seventeen();
eighteen();
}

void 1one(){
fourteen();
seventeen();
}

void 1two(){
twelve();
fourteen();
fifteen();
sixteen();
eighteen();
}

void 1three(){
twelve();
fourteen();
fifteen();
seventeen();
eighteen();
}

void 1four(){
thirteen();
fifteen();
fourteen();
seventeen();
}

void 1five(){
twelve();
thirteen();
fifteen();
seventeen();
eighteen();
}

void 1six(){
twelve();
thirteen();
fifteen();
sixteen();
seventeen();
eighteen();
}


void 1seven(){
twelve();
fourteen();
seventeen();
}

void 1eight(){
twelve();
thirteen();
fourteen();
fifteen();
sixteen();
seventeen();
eighteen();
}
void 1nine(){
twelve();
thirteen();
fourteen();
fifteen();
seventeen();
eighteen();
}

void sixty(){
3one();
colon();
2zero();
1zero();
}

This is what I wrote on a google doc without being able to test it. I know I can run two segments that share pins but in opposite configuration, but I changed the code for each segment to have variables (pin1, pin2) and I don't know for sure if that works, but I assume it does. My only other concern is the name of each reverence code i.e. void 1seven(){ twelve(); fourteen; seventeen();} does the "1seven" work the same as anything else or is that a problem I need to correct. I know as of right now the code does nothing as the void loop is empty, but I have another code I will insert this into that I will use as the actual timer and determiner of what numbers are shown.

I don't think you can start the name of a funding with a digit.

With the approach you are taking, I guess you might be able to get it working, but the code will be enormously long and the display will be very dim and flickery. If this is good enough to get the assignment done, and you have time to finish it, good luck with it.

If you want to know how to make it bright, flicker-free and keep the code short and neat, the forum can help, but it will take some effort to figure out, so let's not attempt that until we know it is needed and be worthwhile.

Sad news guys, the code worked after taking out the second delay in each segment code and taking out the digits in the reference code names, but I believe the clock display is internally messed up because some segments that should not be lighting up are dimly and this messes up the whole system. I am resorting to the small Arduino 4 digit 7 segment display and hoping to resin print a magnifying lense, which is not something I have to focus on. If you can point me towards a working seven segment code for the Arduino one that would be helpful.

I am just using a code from the Circuit Basics website. I am disappointed with the time I've wasted because the project is due on the 18th, but I have learned from this experience.

Google for "arduino sevseg.h"

I’ve already found that and got it displaying, now I just need it to count down from 1 minute and then up to 2 minutes after it reaches 0

And I have things happening as the timer reaches a set time, which I’ve successfully done without the 7 segment display and only a timer going from 60-0

I have the timer working for 60-0 on the 7 segment display with one issue: the digits cycle on and off one at time. I need the to be constantly on and I know the problem but not how to fix it, has to do with my delays in my timer and other parts of the code.

Post the code. It may be possible to drive the display's refresh from a hardware timer so it is insensitive to delay() and other blocking code in the loop(). Better would be to eliminate any blocking code.

It’ll be a few hours before I’m able to send a code, but once I do that, it will be the one I’m in the middle of testing and I won’t be able to take a picture of the circuit I’ve built.

I plan on testing it on tinker CAD circuits later on.

My current theoretical solution is to have the resetDisplay cord in a while loop that has a variable always equal itself so the code is constantly running.

#include "SevSeg.h"
SevSeg sevseg; 
int Counter = 0;
int display = 100;
int maxcount =180;
int i = 0;
int timer = 180;
int button = 0;
int LED1 = 8;
int LED2 = 9;
int C1 = 52;
int C2 = 53;
int interupt = 1;
void setup()
{

  byte numDigits = 4;
  byte digitPins[] = {32, 33, 34, 35};
  byte segmentPins[] = {31, 24, 25, 27, 28, 30, 29, 26};

  bool resistorsOnSegments = true; 
  bool updateWithDelaysIn = false;
  byte hardwareConfig = COMMON_CATHODE; 
  sevseg.begin(hardwareConfig, numDigits, digitPins, segmentPins, resistorsOnSegments);
  sevseg.setBrightness(90);
  
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
  pinMode(C1, INPUT_PULLUP);
  pinMode(C2,INPUT);
 

  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  Counter = 0;
}

void loop()
{
while(  Counter !=0){
  interupt=interupt-1;
delay(1000);
interupt=interupt+1;
delay(1);
}
while( Counter == 0){sevseg.refreshDisplay();
}

  if (digitalRead(C1) == 0 && digitalRead(C2)==HIGH) {
    Counter = 1;
  }
  if (Counter != 0 ) {
  if(timer <=maxcount &&  timer > 0){
     delay(1000);
timer= timer -1;
   
  }
  }
if(timer==maxcount){
   display=100;
   
}
  else if(timer < maxcount && timer >= 120){
    display=timer-120;
}

  if(timer == 0 && Counter != 0){
  digitalWrite(LED1, HIGH);
    
    digitalWrite(LED1, LOW);
    digitalWrite(LED2, HIGH);
    delay(2000); // Wait for 2000 millisecond(s)
    digitalWrite(LED2, LOW);
  }
  if(timer == 0 ){
    Counter = 0;
    timer =maxcount;
  }
  if(interupt == 0){
    
sevseg.refreshDisplay();
  }
  sevseg.setNumber(display, 2);
} ```

I plan to try a few ideas tomorrow. I apologize for it seeming un organized, it's part of a huge project that I am using two arduinos for.

The while loops at the start of the loop are something I know that doesn't work, butI didn't have time to take them out.

This has to be done quite often (say every 4ms or less) otherwise there will be either flicker or the display will freeze. You may be able to drive it in the interrupt service routine of a hardware timer on your what looks like a Mega.

delay() and other blocking statements in the loop are bad. Look at the "blink without delay" sample sketch to see how to use millis() instead.

1 Like