If I'm not mistaken the code is saying if num x is greater or equal to 0 and score is greater or equal to something.
Yes I've tested it on several numbers. inputting 1000 or something like 101010 as myLong values these do display like you would expect them.
I could add code so there is an automatic counter that changes myLong every few seconds like myLong++;
EDIT: i've looked at the no blink example that was here: Gammon Forum : Electronics : Microprocessors : How to do multiple things at once ... like cook bacon and eggs
and I've included this into the code to act as a counter for myLong. now I'm looking at the result on the screen and it's at 171. I've seen 0, 1, 2, 3 etc. 10, 11, 12, 13 etc. 100, 101, 102. As I'm writing this it's now at 211.
So if I'm not mistaken now it works fine?
I will paste the full code.
//We always have to include the libraries we need for this script
#include "STDlib.h"
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc = LedControl(12, 11, 10, 1);
// we always wait a bit between updates of the display
unsigned long delaytime = 250;
// other delay times
int delaytimeshort = 100;
int delaytimemedium = 200;
// variable to use as virtual highscore since we don't have an SD card file yet.
unsigned long myLong = 0;
// setup a routine to use as timer device to increment the myLong value every x seconds.
const unsigned long myLongInterval = 500; // 0,5 seconds.
unsigned long myLongTimer; // holds the time since last change to myLong.
// player scores from previous game (if 0 no game was played so no score display)
unsigned long p1GameOverScore = 1000;
unsigned long p2GameOverScore = 0;
unsigned long p3GameOverScore = 0;
unsigned long p4GameOverScore = 0;
// player scores (to use during gameplay)
unsigned long p1score = 102;
unsigned long p2score = 25;
unsigned long p3score = 3;
unsigned long p4score = 1005;
// balls per game
int BallsPerGame = 5;
// player ball number
int P1Ball = 0;
int P2Ball = 0;
int P3Ball = 0;
int P4Ball = 0;
void setup() {
// in the event we need to display DATA on a computer screen window we need to start serial communications port.
// Serial.begin(9600);
// setup the MAX72XX 7segment 8digit display, wake up the display from power saving mode. (default behaviour)
lc.shutdown(0, false); // wake up from power saving mode
lc.setIntensity(0, 8); // set a brightness value.
lc.clearDisplay(0); // clear the display before use.
// call to other functions during setup phase.
initialiseDisplay();
// setup the myLong timer in millis.
myLongTimer = millis();
}
/*
This void initialiseDisplay() shows to the user the LED Display
is working with a predictable sequence (loops the numbers 0 thru 9 and also shows the decimal point)
*/
void initialiseDisplay()
{
for (int i = 0; i < 10; i++)
{
for (int j = 0; j < 8; j++)
{
lc.setDigit(0, j, i, false); // 0 (we have one LED display), j (the first LED segment on rightmost position), i (what number to display in segment), false (true to display decimal point)
}
delay(delaytimeshort); // we must wait
lc.clearDisplay(0); // and clear the display for next sequence
for (int k = 7; k >= 0; k--)
{
lc.setDigit(0, k, i, true);
}
delay(delaytimeshort); // we must wait
lc.clearDisplay(0); // and clear the display for next sequence
}
}
/*
This method will display every number in a sequence to the LCD.
*/
void displayDemo()
{
for (int number = 0; number < 10; number++)
{
for (int ledNR = 0; ledNR < 9; ledNR++)
{
lc.setDigit(0, ledNR, number, false);
delay(delaytimeshort);
}
lc.clearDisplay(0);
for (int ledNR = 8; ledNR >= 0; ledNR--)
{
lc.setDigit(0, ledNR, number, false);
delay(delaytimeshort);
}
lc.clearDisplay(0);
delay(delaytimemedium);
}
}
void addScore()
{
myLong++;
// remember when we toggled it
myLongTimer = millis ();
}
void displayHighscore()
{
// we want to display a highscore value. (this could be a value stored in a txt file on SD card that we should be retrieving here.)
// there is no SD card module attached to the arduino so we're using a value instead.
// we expect the value to not exceed 99999999 (we have 1 eight digit LCD display currently, that might be expanded to whatever we need maybe 2x 8 digits.)
/* This is used to display the information on the computer serial log screen. Not required for regular operations.
int radix = 10;
char array[9];
ltoa(myLong, array, radix);
Serial.println("HighScore:");
Serial.println(array);
Serial.println("As individuals:");
Serial.println(array[0]);
Serial.println(array[1]);
Serial.println(array[2]);
Serial.println(array[3]);
Serial.println(array[4]);
Serial.println(array[5]);
Serial.println(array[6]);
Serial.println(array[7]);
*/
// Split up the numbers num8 represents the smallets number, num1 represents the largest number.
int num8 = (myLong / 1) % 10;
int num7 = (myLong / 10) % 10;
int num6 = (myLong / 100) % 10;
int num5 = (myLong / 1000) % 10;
int num4 = (myLong / 10000) % 10;
int num3 = (myLong / 100000) % 10;
int num2 = (myLong / 1000000) % 10;
int num1 = (myLong / 10000000) % 10;
// Spell HI SCORE.
lc.setChar(0, 7, 'H', false); // H
lc.setDigit(0, 6, 1, false); // I
lc.setRow(0, 4, B01011011); // S
lc.setRow(0, 3, B01001110); // C
lc.setDigit(0, 2, 0, false); // O
lc.setRow(0, 1, B01110111); // R
lc.setChar(0, 0, 'E', true); // E
delay(2500);
lc.clearDisplay(0);
if (num1 > 0)
{
lc.setDigit(0, 7, num1, false);
}
if (num2 >= 0 and myLong >= 1000000)
{
lc.setDigit(0, 6, num2, false);
}
if (num3 >= 0 and myLong >= 100000)
{
lc.setDigit(0, 5, num3, false);
}
if (num4 >= 0 and myLong >= 10000)
{
lc.setDigit(0, 4, num4, false);
}
if (num5 >= 0 and myLong >= 1000)
{
lc.setDigit(0, 3, num5, false);
}
if (num6 >= 0 and myLong >= 100)
{
lc.setDigit(0, 2, num6, false);
}
if (num7 >= 0 and myLong >= 10)
{
lc.setDigit(0, 1, num7, false);
}
if (num8 >= 0 and myLong >= 0)
{
lc.setDigit(0, 0, num8, false);
}
delay(5000);
lc.clearDisplay(0);
}
void displayScore()
{
// Split up the numbers num8 represents the smallets number, num1 represents the largest number.
int num8 = (myLong / 1) % 10;
int num7 = (myLong / 10) % 10;
int num6 = (myLong / 100) % 10;
int num5 = (myLong / 1000) % 10;
int num4 = (myLong / 10000) % 10;
int num3 = (myLong / 100000) % 10;
int num2 = (myLong / 1000000) % 10;
int num1 = (myLong / 10000000) % 10;
// Display the score
if (num1 > 0)
{
lc.setDigit(0, 7, num1, false);
}
if (num2 >= 0 and myLong >= 1000000)
{
lc.setDigit(0, 6, num2, false);
}
if (num3 >= 0 and myLong >= 100000)
{
lc.setDigit(0, 5, num3, false);
}
if (num4 >= 0 and myLong >= 10000)
{
lc.setDigit(0, 4, num4, false);
}
if (num5 >= 0 and myLong >= 1000)
{
lc.setDigit(0, 3, num5, false);
}
if (num6 >= 0 and myLong >= 100)
{
lc.setDigit(0, 2, num6, false);
}
if (num7 >= 0 and myLong >= 10)
{
lc.setDigit(0, 1, num7, false);
}
if (num8 >= 0 and myLong >= 0)
{
lc.setDigit(0, 0, num8, false);
}
delay(1000);
lc.clearDisplay(0);
}
void loop() {
// displayDemo(); // comment away if you want to see it.
// displayHighscore(); // comment away if you want to see it.
// the following if statement checks if addScore() and displayScore() can be executed.
if ((millis () - myLongTimer) >= myLongInterval)
{
addScore();
displayScore();
}
}