I’m trying to combine these 2 sketches, and I’m getting 0 errors but the Scoreboard portion does not work.
(they both work as intended on their own)
Can anyone help me with what I have done wrong in combining the sketches?
Thank you!
#include <TM1637Display.h>
#include <LedControl.h>
#define numberofseconds(time) ((time / 1000) % 60)
#define numberofminutes(time) (((time / 1000) /60) % 60)
#define gameled 13
const uint8_t ZEROS = {0b00111111, 0b00111111, 0b00111111, 0b00111111 };
const uint8_t OFF = {0, 0, 0, 0};
// in the libary, the byte order is .GFEDCBA
// .GFEDCBA
const uint8_t PLAY = {B01110011, B00111000, B01110111, B01101110};
LedControl lc=LedControl(12,11,10,1); // (DIN, CLK, LOAD, number of Max7219 chips)
// Variable to hold current scores
int displayone=0;
int displaytwo=0;
// Variables to split whole number into single digits
int rightdigit;
int leftdigit;
// Switches pin connection to Arduino UNO
#define switchone 2
#define switchtwo 3
//clock, data
TM1637Display display(7, 6);
// 1000ms in one sec, 1000x60x60 = 3600000ms = 1hour 300000 = 5min
const unsigned long timeLimit = 60000;
unsigned long timeStart;
bool bcountdownDone;
void setup()
{
Serial.begin(9600);
display.setBrightness(0x0d);
display.setSegments(OFF);
pinMode(gameled, OUTPUT);
display.setSegments(PLAY);
timeStart = millis(); //used to time display of PLAY
pinMode(switchone,INPUT_PULLUP);
pinMode(switchtwo,INPUT_PULLUP);
lc.shutdown(0,false); // Wake up MAX7219
lc.setIntensity(0,7); // Set brightness to medium
lc.clearDisplay(0); // Clear all displays connected to MAX7219 chip #
// Put zeros on both displays at startup
lc.setDigit(0,0,0,false); // (Max7219 chip #, Digit, value, DP on or off)
lc.setDigit(0,1,0,false);
lc.setDigit(0,2,0,false);
lc.setDigit(0,3,0,false);
}//setup
#define ST_SHOWPLAY 0
#define ST_COUNT 1
#define ST_FLASH_ZEROS 2
void countdown()
{
static byte
stateCountdown = ST_SHOWPLAY;
//the vars used by countdown state
static bool
bcountdownDone = false;
int
seconds,
minutes;
static int
lastseconds = -1;
unsigned long
timeRemaining,
timeElapsed;
switch( stateCountdown )
{
case ST_SHOWPLAY:
//PLAY is showing from setup…time to start countdown?
if( (millis() - timeStart) > 2000 )
{
stateCountdown = ST_COUNT;
timeStart = millis();
}//if
break;
case ST_COUNT:
timeElapsed = millis() - timeStart;
timeRemaining = timeLimit - timeElapsed;
seconds = numberofseconds(timeRemaining);
minutes = numberofminutes(timeRemaining);
if( seconds != lastseconds )
{
lastseconds = seconds;
display.showNumberDecEx(seconds, 0, true, 2, 2);
display.showNumberDecEx(minutes, 0x80>>3, true, 2, 0);
}//if
if( seconds == 0 && minutes == 0 )
{
digitalWrite( gameled, HIGH );
stateCountdown = ST_FLASH_ZEROS;
}//if
break;
case ST_FLASH_ZEROS:
FlashZeros();
break;
}//switch
}//countdown
void loop()
{
countdown();
}//loop
void FlashZeros( void )
{
static bool
bState = true; //reflect that countdown left digits at 0000 to begin
static unsigned long
timeFlash = 0;
if( millis() - timeFlash > 300 )
{
timeFlash = millis();
if( bState )
{
display.setSegments(OFF);
bState = false;
}//if
else
{
display.setSegments(ZEROS);
bState = true;
}//else
}//if
// If switch 1 is clicked
if (!digitalRead(switchone)) {
displayone++; // Increase score by 1
// convert whole number to single digits
rightdigit=displayone%100/10;
leftdigit=displayone%10;
// Display extracted digits on the display
lc.setDigit(0,0,leftdigit,false);
lc.setDigit(0,1,rightdigit,false);
// Wait until switch is released to continue
while (!digitalRead(switchone)) {
}
delay(5); // Small delay to debounce the switch
}
if (!digitalRead(switchtwo)) {
displaytwo++;
rightdigit=displaytwo%100/10;
leftdigit=displaytwo%10;
lc.setDigit(0,2,leftdigit,false);
lc.setDigit(0,3,rightdigit,false);
while (!digitalRead(switchtwo)) {
}
delay(5);
}
}//FlashZeros