Help with Merger

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

I'm sure you know what "these two sketches" are (I can only see one) and what the program is supposed to do and what "the Scoreboard portion" means and in what way it "does not work" but I'm not good at guessing games. A lot more details might be helpful.

Steve

Yes! There is only one sketch -- one setup() function and one loop() function.

GolamMostafa:
Yes! There is only one sketch – one setup() function and one loop() function.

Sorry, it would not let me post the other two (word cap)

Scoreboard:

#include <LedControl.h>

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

void setup() {
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);

}

void loop() {

// 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);
}
}

Clock:

#include <TM1637Display.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};

//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

}//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

}//FlashZeros

Better but it would be better still if you edited your posts to put the code in </> code tags not as tables.

Now, in detail, what is the combined program supposed to do and what does it actually do? We don’t all have the same hardware and setup as you so we can’t do your testing for you. You need to tell us what the problems are.

Steve

slipstick:
Better but it would be better still if you edited your posts to put the code in </> code tags not as tables.

Now, in detail, what is the combined program supposed to do and what does it actually do? We don’t all have the same hardware and setup as you so we can’t do your testing for you. You need to tell us what the problems are.

Steve

It’s a scoreboard. with a built in clock, using 2, 2digit seven segment delays running off a max7219. the countdown timer or clock, is running off of a tm1637 display module.

The scoreboard is a simple counter counting from 00 to 99 when triggered by pin(s) 2 and 3. using pins 10-12 for the max7219.

The clock module connected to pins 6 and 7. Is a simple count down timer that displays the word “play” and then counts down from a set time. For testing it is set to one min (in the sketch). When it reaches “0” it flashes “0000” and lights an led in pin 13.

All are supposed to run together, using the reset (button/pin) to 0 out the score and start a new game.

The problem in the combined sketch (first one posted) is the clock section functions properly, however the scoreboard, or counter section, does not. it runs the set up, and lights up the displays as intended, but will not count up. However Im getting 0 errors to start to inform me where I went wrong putting the two together and don’t have enough experience with combining sketches to know where to start.