Good day to all!!
I am new to programming and I am trying to program a basketball shot clock and a game clock. I am doing the code for the Basketball Shot clock before the Game clock. I googled for such codes and i didnt find some codes that is much related to what i desired.
By the way i have 3 buttons for the Shot clock, 1st button to countdown from 24sec to 0 , 2nd button is to countdown 14 sec to 0, and the last button is to pause and resume countdown. i am doing it wirelessly using xbee s2c.
The display is a 12 v 2 digit multiplexed seven segment. but i am trying it first to appear in the serial monitor.
The problem is that when i pushed the first button it countdowns from 24 to 0 in the serial monitor and upon pressing the 2nd button, the countdown is still from 24 to 0 and not 14-0. also i want to pause the countdown and resume countdown but i find it difficult on what function is to be used.
This is the code for the display
const int SER=8;
const int LATCH=9;
const int CLK=10;
int j;
int m;
const byte seg[] ={0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101,0b01111101,0b00000111,0b01111111,0b01101111,
0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101,0b01111101,0b00000111,0b01111111,0b01101111,
0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101,0b01111101,0b00000111,0b01111111,0b01101111};
const byte seg1[] ={0b00111111,0b00000110,0b01011011,0b01001111,0b01100110,0b01101101,0b01111101,0b00000111,0b01111111,0b01101111};
void setup() {
Serial.begin(9600);
pinMode(SER, OUTPUT);
pinMode(LATCH, OUTPUT);
pinMode(CLK, OUTPUT);
digitalWrite(LATCH, LOW);
shiftOut(SER, CLK, MSBFIRST, seg[4]);
shiftOut(SER, CLK, MSBFIRST, seg1[2]);
digitalWrite(LATCH, HIGH);
}
void loop() {
if(Serial.available()>0)
{
char inChar=Serial.read();
while(Serial.available()<=0);
//24 seconds
if(inChar=='P')
{
for(j=24; j>=0; j--)
{
digitalWrite(LATCH, LOW);
shiftOut(SER, CLK, MSBFIRST, seg[j%10]); // ones
shiftOut(SER, CLK, MSBFIRST, seg1[j/10]); // tens
digitalWrite(LATCH, HIGH);
Serial.println(j);
delay(1000);
}
}
//14 seconds
if(inChar=='Q')
{
for ( m=14; m>=0; m--)
{
digitalWrite(LATCH, LOW);
shiftOut(SER, CLK, MSBFIRST, seg[m%10]); // ones
shiftOut(SER, CLK, MSBFIRST, se23[m/10]); // tens
digitalWrite(LATCH, HIGH);
Serial.println(m);
delay(1000); // wait a second before incrementing
}
}
}
}
and this is the code for the controller
const int button1= 2;
const int button2=3;
int button1State;
int lastbutton1State = LOW;
int button2State;
int lastbutton2State = LOW;
long lastbutton1DebounceTime = 0;
long debouncebutton1Delay = 50;
long lastbutton2DebounceTime = 0;
long debouncebutton2Delay = 50;
void setup() {
Serial.begin(9600);
pinMode(sbutton1, INPUT);
pinMode(button2, INPUT);
}
void loop() {
// read the state of the switch into a local variable:
int readingbutton1 = digitalRead(button1);
int readingbutton2 = digitalRead(button2);
//24 seconds
if (readingbutton1 != lastbutton1State) {
lastbutton1DebounceTime = millis();
}
if ((millis() - lastbutton1DebounceTime) > debouncebutton1Delay)
{
if (readingbutton1 != button1State)
{
button1State = readingbutton1;
if (button1State == HIGH && button2State==LOW)
{
Serial.println('P');
}
}
}
//14 seconds
if (readingbutton2 != lastbutton2State) {
lastbutton2DebounceTime = millis();
}
if ((millis() - lastbutton2DebounceTime) > debouncebutton2Delay)
{
if (readingbutton2 != button2State)
{
button2State = readingbutton2;
if (button2State == HIGH && button1State==LOW)
{
Serial.println('Q');
}
}
}
lastbutton1State = readingbutton1;
lastbutton2State = readingbutton2;
}
I dont have any program code for the pause and resume button because i am having a problem with this one. can anyone help me pls.