The size and scope of my scoreboard project has changed and I will now be using 4 MAX7219 8x8 LED matrices for the display. Two units for each scores digits. Chips 3 & 2 for the Red (left) digits and chips 1 & 0 for the Blue (right) digits. I've been trying to modify the code from the 7 segment to Matrix but I'm not having much luck as it is currently beyond my limited Arduino coding experience. I've added the digits 1 thru 0 into an array but do not know how to get them to show up on the display. When the buttons are pressed the displays are changing but not displaying the numbers. I'm not sure how to get it to display "byte zero" from the array for the digit zero etc.
I've also put frames into an array for a simple coin flip animation and arrows to point left or right at random for the winner but haven't finished. My main concern is getting the scoreboard digits to work first and the coin toss and possible scrolling text on startup for later.
Any help would be very much appreciated.
Thanks,
Jerry
#include "LedControl.h" // Library used for communcation with LED matrices
int DIN=12; //initialize data (load) to pin 12
int CLK=11; //initialize clock to pin 11
int CS=10; //initialize chip select to pin 10
int MAX=4; //number of displays connected
int bright=1; // LED Brightness 1-15
int delayTime1=5; // Short delay to debounce button push
int delayTime2=75; // Delay between coin frame animation (order 1,2,3,4,1,2,3,4 for each revolution ending on frame 1)
int delayTime3=1000; // Delay on beginning and end of animation
int delaytime4-3000; //Delay after arrow is displayed
LedControl lc=LedControl(DIN,CLK,CS,MAX); // Pins: DIN,CLK,CS, # of Display connected
// Variable to hold current scores
int scoreRed=0;
int scoreBlue=0;
// Variables to split whole number into single digits
int rightdigit;
int leftdigit;
// Switches pin connection to Arduino UNO
#define redUp 2
#define redDown 3
#define redReset 4
#define blueUp 5
#define blueDown 6
#define blueReset 7
#define flipButton 8
// Digits 0-9 rotated to the right 90 degrees
byte one[]={B00000000,B00000000,B10000010,B11111111,B10000000,B00000000,B00000000,B00000000};
byte two[]={B00000000,B10000010,B11000001,B10100001,B10010001,B10001110,B00000000,B00000000};
byte three[]={B00000000,B01000010,B10000001,B10001001,B10001001,B01110110,B00000000,B00000000};
byte four[]={B00000000,B00110000,B00101000,B00100100,B00100010,B11111111,B00000000,B00000000};
byte five[]={B00000000,B01001111,B10001001,B10001001,B10001001,B01110001,B00000000,B00000000};
byte six[]={B00000000,B01111110,B10001001,B10001001,B10001001,B01110010,B00000000,B00000000};
byte seven[]={B00000000,B00000001,B11100001,B00010001,B00001001,B00000111,B00000000,B00000000};
byte eight[]={B00000000,B01110110,B10001001,B10001001,B10001001,B01110110,B00000000,B00000000};
byte nine[]={B00000000,B01001110,B10010001,B10010001,B10010001,B01111110,B00000000,B00000000};
byte zero[]={B00000000,B01111110,B10000001,B10000001,B10000001,B01111110,B00000000,B00000000};
// Coin Frames 1-4 & Left/Right Arrows
byte Coin1[] = {B00011000,B00011000,B00011000,B00011000,B00011000,B00011000,B00011000,B00011000};
byte Coin2[] = {B00000010,B00000111,B00001110,B00011100,B00111000,B01110000,B11100000,B01000000};
byte Coin3[] = {B00000000,B00000000,B00000000,B11111111,B11111111,B00000000,B00000000,B00000000};
byte Coin4[] = {B01000000,B11100000,B01110000,B00111000,B00011100,B00001110,B00000111,B00000010};
byte LTARW[] = {B00111000,B00111000,B00111000,B00111000,B11111110,B01111100,B00111000,B00010000}; //Left Arrow Rotated
byte RTARW[] = {B00010000,B00111000,B01111100,B11111110,B00111000,B00111000,B00111000,B00111000}; //Right Arrow Rotated
void setup() {
pinMode(redUp,INPUT_PULLUP);
pinMode(redDown,INPUT_PULLUP);
pinMode(redReset,INPUT_PULLUP);
pinMode(blueUp,INPUT_PULLUP);
pinMode(blueDown,INPUT_PULLUP);
pinMode(blueReset,INPUT_PULLUP);
pinMode(flipButton,INPUT_PULLUP);
lc.shutdown(0,false); // Wake up displays
lc.shutdown(1,false);
lc.shutdown(2,false);
lc.shutdown(3,false);
lc.setIntensity(0,bright); // Set intensity levels
lc.setIntensity(1,bright);
lc.setIntensity(2,bright);
lc.setIntensity(3,bright);
lc.clearDisplay(0); // Clear Displays
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
// Put zeros on both displays at startup
lc.setDigit(3,3,0,false); // (Max7219 chip #, Digit, value, DP on or off) Red Score
lc.setDigit(2,2,0,false);
lc.setDigit(1,1,0,false); // (Max7219 chip #, Digit, value, DP on or off) Blue Score
lc.setDigit(0,0,0,false);
}
void loop() {
// If switch redUp is clicked
if (!digitalRead(redUp)) {
scoreRed++; // Increase scoreRed by 1
// convert whole number to single digits
rightdigit=scoreRed%10;
leftdigit=scoreRed%100/10;
// Display extracted digits on the display
lc.setDigit(3,3,leftdigit,false);
lc.setDigit(2,2,rightdigit,false);
// Wait until switch is released to continue
while (!digitalRead(redUp)) {
}
delay(delayTime1); // Small delay to debounce the switch
}
// If switch redDown is clicked
if (!digitalRead(redDown)) {
scoreRed--; // Decrease scoreRed by 1
// convert whole number to single digits
rightdigit=scoreRed%10;
leftdigit=scoreRed%100/10;
// Display extracted digits on the display
lc.setDigit(3,3,leftdigit,false);
lc.setDigit(2,2,rightdigit,false);
// Wait until switch is released to continue
while (!digitalRead(redDown)) {
}
delay(delayTime1); // Small delay to debounce the switch
}
// If switch redReset is clicked
if (!digitalRead(redReset)) {
scoreRed=00; // Reset scoreRed to 0
lc.setDigit(3,3,0,false);
lc.setDigit(2,2,0,false);
// Wait until switch is released to continue
while (!digitalRead(redReset)) {
}
delay(delayTime1); // Small delay to debounce the switch
}
// If switch blueUp is clicked
if (!digitalRead(blueUp)) {
scoreBlue++; // Increase scoreBlue by 1
// convert whole number to single digits
rightdigit=scoreBlue%10;
leftdigit=scoreBlue%100/10;
// Display extracted digits on the display
lc.setDigit(1,1,leftdigit,false);
lc.setDigit(0,0,rightdigit,false);
// Wait until switch is released to continue
while (!digitalRead(blueUp)) {
}
delay(delayTime1); // Small delay to debounce the switch
}
// If switch blueDown is clicked
if (!digitalRead(blueDown)) {
scoreBlue--; // Decrease scoreBlue by 1
// convert whole number to single digits
rightdigit=scoreBlue%10;
leftdigit=scoreBlue%100/10;
// Display extracted digits on the display
lc.setDigit(1,1,leftdigit,false);
lc.setDigit(0,0,rightdigit,false);
// Wait until switch is released to continue
while (!digitalRead(blueDown)) {
}
delay(delayTime1); // Small delay to debounce the switch
}
// If switch blueReset is clicked
if (!digitalRead(blueReset)) {
scoreBlue=00; // Reset scoreBlue to 0
lc.setDigit(1,1,0,false);
lc.setDigit(0,0,0,false);
// Wait until switch is released to continue
while (!digitalRead(blueReset)) {
}
delay(delayTime1); // Small delay to debounce the switch
}
}
