Life2Coding
Basketball Shot Clock – Implementing Prototype

Basketball Shot Clock – Implementing Prototype. This project will show you how to create your own basketball shot clock. It has a buzzer alarm to indicate the time elapsed and it also been integrated to use with only just one 7474 IC unlike what I have showed you from the youtube link I provided. Also the buzzer alarm wasn’t shown but you will know it how to attach because at bottom I provided you source code.

We also created basketball game clock and can find it HERE.

This project was tested and working in real hardware 100%; which means you can package this for commercial use but don’t forget to give where the credit is due – thank you!

For the materials used for this  project was also provided through the schematic shown below.

 

SCHEMATIC DIAGRAM:

Sketch Basketball Shot Clock - Implementing Prototype

Θ CODE:

main.ino

/***
 * 
    BasketBall 24 and 14 Seconds Shot Clock with Buzzer Alarm
    
    Support us: Life2Coding.com
 * 
***/

//Declaring and Initializing Variables
int p4 = 4;
int p5 = 5;
int p6 = 6;
int p7 = 7;
int p9 = 9;
int p10 = 10;
int Buzzer = 12;
boolean Standby = true;
unsigned long newTime,oldTime=0;
const long timeDelay=1000;
volatile int Num1 = 0;
volatile int Num2 = 0;
volatile int Zero = 0;
volatile byte Press = 0;
volatile boolean Ready = false;
volatile boolean Shifter = false;
volatile int Shift = 8;


void setup() {
  pinMode(Shift, INPUT);//Shift pin button
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  
  pinMode(9, OUTPUT);//FirstDigit
  pinMode(10, OUTPUT);//SecondDigit
  
  pinMode(12, OUTPUT);//Buzzer
  attachInterrupt(0, Starting, HIGH);
  attachInterrupt(1, ReStarting, RISING);
  digitalWrite(12,LOW);//Set it LOW first
}

void refresh(){
SecondDigit();
FirstDigit();
}

void Starting() {
  //Running and Stopping here
  if (Ready == false) {
    Press = 0;
  }

  Press++;
  if (Press >= 4) Press = 2;
} //End of Starting

void ReStarting() {
  //Restart sequence
  Zero = 0;
  if (Press == 0) {
    Num2 = 2;
    Num1 = 4;
    Ready = true;
    Press = 1;

  }
  
  if (digitalRead(Shift) == HIGH) Shifter = true;

if(Shifter==false){
  if(Zero==3)Press=1;
  Num1=4;
  Num2=2;
  Zero=0;
  Ready=true;
  Press=Press;
}
  else{
    if(Press==2){
       if((Num1+(Num2*10))<14){
    Num1=4;
    Num2=1;
    Zero=1;
    Ready=true;
    Press=2;
    } 
    }
    else{
    if(Press==1 || Press==3){
      //Uncomment the next line to disable the 14 seconds reset if time is greater than 14 seconds
    if((Num1+(Num2*10))<14){
    Num1=4;
    Num2=1;
    Zero=1;
    Ready=true;
    Press=1;
    }
  }
}
  }  
}//End of ReStarting


void Display() {
  if (Press == 2) {
    if (Zero <= 3) {
      Num1--;
      if (Num1 == 0)Zero++;
      if (Num1 == -1) {
        Num1 = 9;
        if (Num2 > 0)Num2--;

      }
    }
  }
  for (int Transition = 0; Transition < 500; Transition++) {
        FirstDigit();
        SecondDigit();
        if (Ready == true) {
    
      if (Zero == 3)BuzzMaker();
    }
  }
} //End of Display


void FirstDigit() {
  //Display 4 BCD digits of Number in First LED Segment
  digitalWrite(10, LOW);
  digitalWrite(9,HIGH);
  if (digitalRead(Shift) == HIGH) Shifter = true;
  digitalWrite(4, bitRead(Num1, 0));
  digitalWrite(5, bitRead(Num1, 1));
  digitalWrite(6, bitRead(Num1, 2));
  digitalWrite(7, bitRead(Num1, 3));
  delay(1);
  Shifter = false;
} //End of FirstDigit


void SecondDigit() {
  //Display 4 BCD digits of Number in Second LED Segment
  digitalWrite(9,LOW);
  digitalWrite(10, HIGH);
  if (digitalRead(Shift) == HIGH) Shifter = true;
  digitalWrite(4, bitRead(Num2, 0));
  digitalWrite(5, bitRead(Num2, 1));
  digitalWrite(6, bitRead(Num2, 2));
  digitalWrite(7, bitRead(Num2, 3));
  delay(1);
  Shifter = false;
} //End of SecondDigit

void BuzzMaker() {
  //Configuring Buzzer frequency and setting go with the counting numerals
    digitalWrite(9,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(12,HIGH);
        
    delay(1000);
    digitalWrite(12,LOW);
    delay(200);
    digitalWrite(12,HIGH);
        
    delay(500);
    digitalWrite(12,LOW);

    Press=2;
    Zero=0;
  Ready=true;
  Shifter=false;
}//End of BuzzMaker


void loop() {
if(Press==0)refresh;
refresh();
  newTime=millis();
if((newTime-oldTime)>=timeDelay){
  oldTime=newTime;
  
   if(Num2==0 && Num1==0 && Press==2){
 
  Press=1;
}

//Here we are going to access each case with each different routine by case
  switch (Press) {

    case 0://Initial

      Display();
      break;

    case 1://Stop - Displaying 24 but still not yet running

      Display();
      break;

    case 2://Running

      Display();
     // PlayTime();
      break;

  }
}//End of millis() condition

} //End of main loop function


The following video shows the demo of this post:

 

 

james-pic Basketball Shot Clock - Implementing Prototype

2 thoughts on “Basketball Shot Clock – Implementing Prototype

  1. Pingback: Basketball Game Clock - Implementing Prototype - Life2Coding

  2. Achala uthsuka

    Hi ! Dear James,

    i am achala from sri lanka… enthusiast who look for new things… i saw this and it’s pretty challenging… so i try to remake the circuit but i am on serious troubles… circuit is not complete and in the video there you using two IC’s … can you kindly help me … my mail is uthsuka@live.com

    thanks
    achala

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.