Introduction: Table Tennis Score Board

Picture of Table Tennis Score Board

This is a 3 buttons control table-tennis score board, 1st player, 2nd player and reset.
You will need :
X3 220ohm resistors
X3 Push Buttons
X1 Dual (8 digits) max7291 7-segment display
an Arduino, the diagram shows UNO but i only used it at the planning level, afterword i changed to pro-Micro
Some Cables.

Step 1: It Is Simple

Picture of It Is Simple

The program increase each player score every time the player button is pushed.
if eather of the player reached 11 points and the score differents is bigger then 2 then the game counter is increased and a new match begins.

Step 2: Code....

#define MAX7219_DIN 5
#define MAX7219_CS  6
#define MAX7219_CLK 7
#define leftB 8
#define rightB 9
#define RESETb 10
int left, right, rightPlay, leftPlay = 0;
boolean changeIndc = false;
int SRead;
void initialise()
{
  digitalWrite(MAX7219_CS, HIGH);
  pinMode(MAX7219_DIN, OUTPUT);
  pinMode(MAX7219_CS, OUTPUT);
  pinMode(MAX7219_CLK, OUTPUT);
}
void output(byte address, byte data)
{
  digitalWrite(MAX7219_CS, LOW);
  shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, address);
  shiftOut(MAX7219_DIN, MAX7219_CLK, MSBFIRST, data);
  digitalWrite(MAX7219_CS, HIGH);
}
void setup() {
  Serial.begin (9600);
  pinMode (leftB, INPUT);
  pinMode (rightB, INPUT);
  // put your setup code here, to run once:
  initialise();
  output(0x0f, 0x00); //display test register - test mode off
  output(0x0c, 0x01); //shutdown register - normal operation
  output(0x0b, 0x07); //scan limit register - display digits 0 thru 7
  output(0x0a, 0x0f); //intensity register - max brightness
  output(0x09, 0xff); //decode mode register - CodeB decode all digits
  output(0x08, 0x00); //digit 7 (leftmost digit) data
  output(0x07, 0x0a);
  output(0x06, 0x00);
  output(0x05, 0x00);
  output(0x04, 0x00);
  output(0x03, 0x00);
  output(0x02, 0x0a);
  output(0x01, 0x00); //digit 0 (rightmost digit) data
}
void loop() {
  SRead = Serial.read ();
  
  if (SRead ==48 || digitalRead (RESETb)) {
    Serial.println ("RESET");
    left = 0;
    right = 0;
    leftPlay = 0;
    rightPlay = 0;
    changeIndc = true;
    output (0x01, 0);
    output (0x08, 0);
  }
  
  if (SRead == 49 || digitalRead (leftB)) {
    delay (200);
    while (digitalRead (leftB)) {}
    left++;
    changeIndc = true;
  }
  if (SRead == 50 || digitalRead (rightB)) {
    delay (200);
    while (digitalRead (rightB)) {}
    right++;
    changeIndc = true;
  }
  
  if (changeIndc) {
       output(0x03, left % 10);
       output(0x04, left / 10);
   
      output(0x05, right % 10);
      output(0x06, right / 10);
    
    if (right >=11 && right >= left +2) {
     rightPlay ++; 
     right = 0;
     left = 0;
     output (0x08, rightPlay);
    }
    
    if (left >=11 && left >= right + 2) {
     leftPlay ++; 
     right = 0;
     left = 0;
     output (0x01, leftPlay);
    }
    
    changeIndc = false;
  }
}

Comments

ashton1o (author)2017-05-05

Cool I love coding what else can I make it do

About This Instructable

752views

4favorites

License:

More by udubinsky:ENC28J60 Using Ethernet With ArduinoElectro Double Pie Face Showdown Never Forget It on - Energy Saver
Add instructable to: