7-Segment LED Scoreboard - My First Project

Using the SURE Electronics 2.3" 2 Digit 7-Segment LED Display Board (DE-DP22811). It is being powered by the test board that comes with the 4 Digit board.

The program will keep score (up to 21). I am not a programmer, and I am sure some code could be written better. And if you have suggestions on what could be written better, please feel free to comment.

// Button Inputs
const int p1IncPIN=5, p1DecPIN=6, p2IncPIN=7, p2DecPIN=8;
// variable for reading the button status
int p1IncButton=0, p1DecButton=0, p2IncButton=0, p2DecButton=0;
// Video Outputs and Video Data
const int ledClockPIN=10; // to pin 10 on J1 (CLK_IN)
const int ledDataPIN=9;   // to pin 9 on J1 (DATA_IN)
const int ledLatchPIN=3;  // to pin 7 on J1 (DIMM_IN)
// Display Digit HEX Code {0-9} for Sure Electronics 12v 2-Panel 7-Segment Board
static byte displayDigit[10] = {
    0x3f, // 0
    0x06, // 1
    0x5b, // 2
    0x4f, // 3
    0x66, // 4
    0x6d, // 5
    0x7d, // 6
    0x07, // 7
    0x7f, // 8
    0x6f  // 9
  }; 
//set hex variable initial value
int p2_Ones=0, p2_Tens=0, p1_Ones=0, p1_Tens=0;
// set the variables for the score
int player1Score = 0, player2Score = 0;
// previous state of each button declaration
int p1IncLastButtonState = 0;
int p1DecLastButtonState = 0;
int p2IncLastButtonState = 0;
int p2DecLastButtonState = 0;

void setup(){
  // initialize the pushbutton pin as an input:
  pinMode(p1IncPIN, INPUT);
  pinMode(p1DecPIN, INPUT);
  pinMode(p2IncPIN, INPUT);
  pinMode(p2DecPIN, INPUT);

  // Set the Display Pins as outputs
  pinMode(ledLatchPIN, OUTPUT);//Latch
  pinMode(ledClockPIN, OUTPUT);//Clock
  pinMode(ledDataPIN, OUTPUT);//Data
  digitalWrite(ledLatchPIN, HIGH);
  // Initialize the display to reflect the beginning score before running loop()
  initDisplay();
}

void loop() {  
  //read the Button Pins to see if one of them has been pressed
  p1IncButton = digitalRead(p1IncPIN);
  p1DecButton = digitalRead(p1DecPIN);
  p2IncButton = digitalRead(p2IncPIN);
  p2DecButton = digitalRead(p2DecPIN);
  
  //read the Button Pins to see if one of them has been pressed
 if (p1IncButton != p1IncLastButtonState) {
    // if the state has changed, increment the counter     
    if (p1IncButton == HIGH){
      if (player1Score != 21) player1Score++;
    }
  }

  if (p1DecButton != p1DecLastButtonState) {
    // if the state has changed, increment the counter     
    if (p1DecButton == HIGH){
      if (player1Score != 0) player1Score--;
    }
  }

  if (p2IncButton != p2IncLastButtonState) {
    // if the state has changed, increment the counter     
    if (p2IncButton == HIGH){
      if (player2Score != 21) player2Score++;
    }
  }

  if (p2DecButton != p2DecLastButtonState) {
    // if the state has changed, increment the counter     
    if (p2DecButton == HIGH){
      if (player2Score != 0) player2Score--;
    }
  }
  
  // Check to see if both increment buttons are high - this will reset the score back to 0-0
  if (p1IncButton == HIGH && p2IncButton == HIGH) {
    initDisplay(); 
      // set the variables for the score at the beginning of the game
    player1Score = 0, player2Score = 0;
    
  }
  // save the current state as the last state for next time through the loop
  p1IncLastButtonState = p1IncButton;
  p1DecLastButtonState = p1DecButton;
  p2IncLastButtonState = p2IncButton;
  p2DecLastButtonState = p2DecButton;
  
  delay(50);
  scoreUpdate();
}

void scoreUpdate() {
  // this is used after a button is pressed to update the players score in integer form
  // needed to break down the score to pass info to the screen
  if (player1Score < 10) {
    p1_Tens = 0;
    p1_Ones = player1Score;
  }
  else if (player1Score > 9 && player1Score < 20) {
    p1_Tens = 1;
    p1_Ones = player1Score-10;
  }
  else if (player1Score > 19) {
    p1_Tens = 2;
    p1_Ones = player1Score-20;
  }

  if (player2Score < 10) {
    p2_Tens = 0;
    p2_Ones = player2Score;
  }
  else if (player2Score > 9 && player2Score < 20) {
    p2_Tens = 1;
    p2_Ones = player2Score-10;
  }
  else if (player2Score > 19) {
    p2_Tens = 2;
    p2_Ones = player2Score-20;
  }
  
  // call the scoreToHex function and pass the score variables
  updateLED();
}

void updateLED() { // update the LEDs based upon the information passed from scoreToHex
  digitalWrite(ledLatchPIN, HIGH);
  shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, displayDigit[p2_Ones]);//(datapin, clockpin, data) for Right Panel digit 1 - Player 2 Ones
  
  if (p2_Tens>0) {
    shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, displayDigit[p2_Tens]);//(datapin, clockpin, data) for Right Panel digit 2 - Player 2 Tens
  }
  else {
    shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, 0);//(datapin, clockpin, data) for Right Panel digit 2 - Player 2 Tens
  }    
  
  shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, displayDigit[p1_Ones]);//(datapin, clockpin, data) for Left Panel digit 1 - Player 1 Ones
  
  if (p1_Tens>0) {
    shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, displayDigit[p1_Tens]);//(datapin, clockpin, data) for Right Panel digit 2 - Player 2 Tens
  }
  else {
    shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, 0);//(datapin, clockpin, data) for Right Panel digit 2 - Player 2 Tens
  }      
  
  digitalWrite(ledLatchPIN, LOW);

}

//Initialize the display to show zero's in the one's column
void initDisplay() {
  digitalWrite(ledLatchPIN, HIGH);
  shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, 0x3f);//(datapin, clockpin, data) for Right Panel digit 1 - Player 2 Ones
  shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, 0);//(datapin, clockpin, data) for Right Panel digit 2 - Player 2 Tens
  shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, 0x3f);//(datapin, clockpin, data) for Left Panel digit 1 - Player 1 Ones
  shiftOut(ledDataPIN, ledClockPIN, MSBFIRST, 0);//(datapin, clockpin, data) for Right Panel digit 2 - Player 2 Tens
  digitalWrite(ledLatchPIN, LOW);
}

cool! that's what arduino was made for. The code don't need to be perfect as long as it works :slight_smile:

Look at the Style guide section on this WEB page:

HI, I've always wanted to get into electronics hobby. I'm desperately looking to build a scoreboard exactly like this for my father. Your scoreboard wouldn't happen to be used for cornhole would it? He's retired and loves to play cornhole and wants a digital scoreboard. (we've actually built 6 sets of cornhole for family)

Being new, terminology and understanding of the basics is tough right now, I've only been at it a few days. But I will build one of these, one day!
It's really tough figuring out what IC's are needed or all the components.

Do I build the 7segment display from scratch (which I don't know how to do yet)? Do I skip Arduino completely (though I'm still buying an Arduino kit for some learning), and just use avr programmer. Or what about using two 60x60mm dot matrix displays instead of the two dual 7 segments, like in this project. Dot matrix route would seem less diy circuitry and more programming to me, though I have no idea. And either way doesn't bother me at all. anything you'd do differently? I've got a lot of questions going through my head on this heh.

Anyway, great job on the scoreboard. I saved your code for hopefully future reference one day. Any help or advice from anyone would be appreciated.

Basic scoreboards are simple, I use TPIC6B595 serial latches to drive 7 segment displays with up to 140 LEDs per 14" number.

You can "daisy chain" the chips , with the serial data going through each chip to the next, and when the latch pin goes high, all the numbers light up until the next change of data. ( its not multiplexed )

I run up to 19 digits daisy chained, I experimented with more and found some instability ( due to cable length and capacitance ) when I got to about 28 chips

Look up Shiftout i the learning section, ( but ignore any capacitors on any data line )

Could you please post the wiring as well?

Simple scheme. I use SPI to send the 4 bytes out that are displayed:

digitalWrite(ssPin, LOW);
for (x=0; x<4; x=x+1){
SPI.transfer(fontArray[dataArray[x]]); // double lookup - number to display and font-to-segment mapping
}
digitalWrite (ssPin, HIGH); // outputs change on this rising edge

I have been trying to build the same project (with your help) and I am trying to figure out the wiring diagram. Could you help?

Hi, AzBrewsky
I hope you still onto this,

I have the same scoreboard project but using 74hc595.
What should I change the code ?

The attachment is the 7 segment schematic.

Aprriciate your help

The 74HC595 can't drive scoreboard sized displays.
It's a 5volt chip with a 6mA current limit.
Just ok for small 1" displays.

2.3" displays (and bigger) use multiple LEDs in series per segment.
Segment voltage (LED Vf) could be 8volt or more.
For scoreboards, you need something that can switch a higher voltage and a higher current.
The TPIC6B595 is perfect for that.
Works the same as the 74HC595, but has mosfet outputs that can switch up to 50volt and 150mA.
Look at this project that uses almost the same chip (smd version).

Leo..

I offer a board that combines Arduino function with up to 12 shift registers for drivingup to 12-digit LED-strip displays.
Plug on an FTDI Basic for code downloading/debugging, remove when done.
http://crossroadsfencing.com/BobuinoRev17/index.html

Hi, i know it's been years, but i miss 1 little thing and I could not find it :slight_smile:
I use the same program for scoreboard.
But I use Comman Anoda and I manage to invert the hex with no problem.
everything is working exept when I turn on the first and third digit all segment including DP lights up, which suppost to lights off until it reach 10.

Pressing the bottons players works fine.

I connect the pin 13 to the ground

I can not fine the problem. Anyone can help?

Thank you

"I can not fine the problem. Anyone can help?"

Not without seeing your code.
Also, your display should have current limiting resistors between the 74HC595 and the segments, and a 0.1uF cap from each pin 16 to Gnd.

I use a font Array to map from a digit to the segments:

byte fontArray[] = { // can also add const I suppose
0b00111111, // 0  1 = on, 0 = off  DP-g-f-e-d-c-b-a
0b00000110, // 1
etc
0b01101111, // 9
};
Then to send data out:
[code]
digitalWrite (RCKpin, LOW);
SPI.transfer (fontArray[digit0]); // D13/SCK connect to SRCLK, D11/MOSI connects to Data In
SPI.transfer (fontArray[digit1]); // or, use much slower shiftOut( ) if you must
SPI.transfer (fontArray[digit2]); // SPI.transfer works great, default settings send data out at 4 MHz clock rate
SPI.transfer (fontArray[digit3]); // add #include<SPI.h> at top of the sketch, and SPI.begin(); in setup( )
digitalWrite (RCKpin, HIGH); // outputs update on this rising edge

[/code]

The code is exacly the same as the first post on this thread from azbresky except I change 0x3F to B00111111, // 0
Etc

Yes I know I will use 0.1 uf cap on each segment to the ground.

I use comman Anode 7 segment, 5volt.
The attachment pic. Showing led lit when I turn on.
All digits lit are invert. (The 1st and 3rd digit suppose to be off)
I can not understand why it invert ?
Is it because I'm using comman Anode?

Is there anyway to invert ? The simple way?
Would it solve the problem if I use comman Cathode?
I'm not a programmer for sure.



Those 74hc595 will soon burn and you will have to replace with something better designed.
You have not posted your code, so we can't tell why your segments are inverted, but it would be easy to fix that in the code, for example with ^0xFF

The code is the first post of this thread, the same code.
Yes it will burn the 74hc595 (70ma) maximum and i already order tpic6b595.
Even I'm using 5volt led with 10ma each segment.

I can not make the frist digit and third off, but so far i can change the code with 0, so it become 0000.

AzBrewsky:

Bro i cant find any schematic for this project.. Anyone got schematic

pradoartz:
Bro i cant find any schematic for this project.. Anyone got schematic

Basic use of the 74HC595 (or the TPIC6.... for large size displays).
This page has schematics and code.
Leo..

Hi Everyone,
I have a Sure DP22811 and am confused if I need 2 large digit drivers and 2 shift registers to light up both of my digits.

Thanks,
Dave