//We always have to include the library
#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
***** Please set the number of devices you have *****
But the maximum default of 8 MAX72XX wil also work.
*/
LedControl lc=LedControl(12,11,10,8);
const int pinCLK = 4;
const int pinDT = 5;
/* we always wait a bit between updates of the display */
unsigned long delaytime=500;
byte num[80]={
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B01001110, //⬛🟥⬛⬛🟥🟥🟥⬛
B01011110, //⬛🟥⬛🟥🟥🟥🟥⬛
B01111110, //⬛🟥🟥🟥🟥🟥🟥⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00011000, //⬛⬛⬛🟥🟥⬛⬛⬛
B01111000, //⬛🟥🟥🟥🟥⬛⬛⬛
B00011000, //⬛⬛⬛🟥🟥⬛⬛⬛
B00011000, //⬛⬛⬛🟥🟥⬛⬛⬛
B00011000, //⬛⬛⬛🟥🟥⬛⬛⬛
B01111110, //⬛🟥🟥🟥🟥🟥🟥⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00000110, //⬛⬛⬛⬛⬛🟥🟥⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B01100000, //⬛🟥🟥⬛⬛⬛⬛⬛
B01111110, //⬛🟥🟥🟥🟥🟥🟥⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00001100, //⬛⬛⬛⬛🟥🟥⬛⬛
B00000110, //⬛⬛⬛⬛⬛🟥🟥⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B01101100, //⬛🟥🟥⬛🟥🟥⬛⬛
B01101100, //⬛🟥🟥⬛🟥🟥⬛⬛
B01101100, //⬛🟥🟥⬛🟥🟥⬛⬛
B01111110, //⬛🟥🟥🟥🟥🟥🟥⬛
B00001100, //⬛⬛⬛⬛🟥🟥⬛⬛
B00001100, //⬛⬛⬛⬛🟥🟥⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B01111110, //⬛🟥🟥🟥🟥🟥🟥⬛
B01100000, //⬛🟥🟥⬛⬛⬛⬛⬛
B01111100, //⬛🟥🟥🟥🟥🟥⬛⬛
B00000110, //⬛⬛⬛⬛⬛🟥🟥⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00111110, //⬛⬛🟥🟥🟥🟥🟥⬛
B01100000, //⬛🟥🟥⬛⬛⬛⬛⬛
B01111100, //⬛🟥🟥🟥🟥🟥⬛⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B01111110, //⬛🟥🟥🟥🟥🟥🟥⬛
B00000110, //⬛⬛⬛⬛⬛🟥🟥⬛
B00001100, //⬛⬛⬛⬛🟥🟥⬛⬛
B00011000, //⬛⬛⬛🟥🟥⬛⬛⬛
B00110000, //⬛⬛🟥🟥⬛⬛⬛⬛
B00110000, //⬛⬛🟥🟥⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00000000, //⬛⬛⬛⬛⬛⬛⬛⬛
B00111100, //⬛⬛🟥🟥🟥🟥⬛⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B01100110, //⬛🟥🟥⬛⬛🟥🟥⬛
B00111110, //⬛⬛🟥🟥🟥🟥🟥⬛
B00000110, //⬛⬛⬛⬛⬛🟥🟥⬛
B00000110, //⬛⬛⬛⬛⬛🟥🟥⬛
B00000000}; //⬛⬛⬛⬛⬛⬛⬛⬛
int matrix = 0;
int y = 0;
int randnum1 = 0;
int randnum2 = 0;
int randnum3 = 0;
int currentStateCLK;
int previousStateCLK;
int counter = 0;
int time = 0.0;
int num1 = 2;
int num2 = 8;
int num3 = 7;
bool activateOnce = true;
/*
This time we have more than one device.
But all of them have to be initialized
individually.
*/
void setup() {
pinMode(pinCLK,INPUT);
pinMode(pinDT,INPUT);
//we have already set the number of devices when we created the LedControl
int devices=lc.getDeviceCount();
//we have to init all devices in a loop
for(int address=0;address<devices;address++) {
/*The MAX72XX is in power-saving mode on startup*/
lc.shutdown(address,false);
/* Set the brightness to a medium values */
lc.setIntensity(address,8);
/* and clear the display */
lc.clearDisplay(address);
}
while (!Serial);
Serial.begin(9600);
Serial.println(F("Startup"));
previousStateCLK = digitalRead(pinCLK);
}
//void display(){
// lc.setColumn(matrix,7+y, displaymatrix[0]);
// lc.setColumn(matrix,6+y, displaymatrix[1]);
// lc.setColumn(matrix,5+y, displaymatrix[2]);
// lc.setColumn(matrix,4+y, displaymatrix[3]);
// lc.setColumn(matrix,3+y, displaymatrix[4]);
// lc.setColumn(matrix,2+y, displaymatrix[5]);
// lc.setColumn(matrix,1+y, displaymatrix[6]);
// lc.setColumn(matrix,0+y, displaymatrix[7]);
// }
//void loop() {
//if(time > 9)
//{
// time = 1;
//}else
//{
//time = time + 1;
//}
//
//
//
//
//
//
//
//
//
//
//
//
// //Serial.print("CLK: ");
// //Serial.print(digitalRead(pinCLK));
// //Serial.print(" - DT: ");
// //Serial.print(digitalRead(pinDT));
// //Serial.println();
//
//
// //read the number cascaded devices
// //int devices=lc.getDeviceCount();
// ////display()
// //randnum = random(0,7);
// //lc.clearDisplay(0);
// //lc.setLed(0,randnum,0,true);
// //delay(1000);
//
//
//
// ////we have to init all devices in a loop
// //for(int row=0;row<8;row++) {
// // for(int col=0;col<8;col++) {
// // for(int address=0;address<devices;address++) {
// // delay(delaytime);
// // lc.setLed(address,row,col,true);
// // delay(delaytime);
// // lc.setLed(address,row,col,false);
// // }
// // }
// //}
//}
void loop()
{
time = time + 1;
if(time > 99)
{
time = 0;
}
//randomSeed(time);
currentStateCLK = digitalRead(pinCLK);
if(currentStateCLK != previousStateCLK)
{
if (digitalRead(pinDT) != currentStateCLK)
{
counter --;// diminue la valeur du compteur
}else
{
counter ++;// sinon on l'augmente
}
Serial.print("Value: ");
Serial.println(counter);
if(counter > 4)
{
counter ++;
Serial.print("Value: ");
Serial.println(counter);
Serial.println(time);
randomSeed(time);
Serial.println("More than 4");
//activate here
//if(true == false)
//{
randnum1 = random(1,20);
if(time <= 1)
{
Serial.println("Jackpot");
//Jackpot
num1 = 0;
num2 = 0;
num3 = 0;
} else
{
Serial.println("No Jackpot");
randnum1 = random(1,5);
if(randnum1 <= 1)
{
Serial.println("Mini Jackpot");
//Mini Jackpot
randnum1 = random(1,9);
num1 = randnum1;
num2 = randnum1;
num3 = randnum1;
} else
{
randnum1 = random(1,10);
if(randnum1 <= 2)
{
Serial.println("Nothing");
//Nothing
randomSeed(time);
randnum1 = random(1,9);
for (randnum2 = random(1,9); randnum2 == randnum1 ; randnum2 = random(1,9)){}
for (randnum3 = random(1,9); (randnum3 == randnum2)&&(randnum3 == randnum1); randnum3 = random(1,9)){}
num1 = randnum1;
num2 = randnum2;
num3 = randnum3;
} else
{
//Almost Jackpot
Serial.println("Almost Jackpot");
randnum1 = random(1,9);
for (randnum2 = random(1,9); randnum2 == randnum1; randnum2 = random(1,9)){}
num1 = randnum1;
num2 = randnum1;
num3 = randnum2;
}
}
}
for(int i = 0; i <= 8; i++)
{
lc.setColumn(0,0+8-i, num[num1*8+7]);
lc.setColumn(0,1+8-i, num[num1*8+6]);
lc.setColumn(0,2+8-i, num[num1*8+5]);
lc.setColumn(0,3+8-i, num[num1*8+4]);
lc.setColumn(0,4+8-i, num[num1*8+3]);
lc.setColumn(0,5+8-i, num[num1*8+2]);
lc.setColumn(0,6+8-i, num[num1*8+1]);
lc.setColumn(0,7+8-i, num[num1*8+0]);
}
delay(200);
for(int i = 0; i <= 8; i++)
{
lc.setColumn(1,0+8-i, num[num2*8+7]);
lc.setColumn(1,1+8-i, num[num2*8+6]);
lc.setColumn(1,2+8-i, num[num2*8+5]);
lc.setColumn(1,3+8-i, num[num2*8+4]);
lc.setColumn(1,4+8-i, num[num2*8+3]);
lc.setColumn(1,5+8-i, num[num2*8+2]);
lc.setColumn(1,6+8-i, num[num2*8+1]);
lc.setColumn(1,7+8-i, num[num2*8+0]);
}
//lc.setColumn(1,0, num[num2*8+7]);
//lc.setColumn(1,1, num[num2*8+6]);
//lc.setColumn(1,2, num[num2*8+5]);
//lc.setColumn(1,3, num[num2*8+4]);
//lc.setColumn(1,4, num[num2*8+3]);
//lc.setColumn(1,5, num[num2*8+2]);
//lc.setColumn(1,6, num[num2*8+1]);
//lc.setColumn(1,7, num[num2*8+0]);
delay(200);
for(int i = 0; i <= 8; i++)
{
lc.setColumn(2,0+8-i, num[num3*8+7]);
lc.setColumn(2,1+8-i, num[num3*8+6]);
lc.setColumn(2,2+8-i, num[num3*8+5]);
lc.setColumn(2,3+8-i, num[num3*8+4]);
lc.setColumn(2,4+8-i, num[num3*8+3]);
lc.setColumn(2,5+8-i, num[num3*8+2]);
lc.setColumn(2,6+8-i, num[num3*8+1]);
lc.setColumn(2,7+8-i, num[num3*8+0]);
}
//lc.setColumn(2,0, num[num3*8+7]);
//lc.setColumn(2,1, num[num3*8+6]);
//lc.setColumn(2,2, num[num3*8+5]);
//lc.setColumn(2,3, num[num3*8+4]);
//lc.setColumn(2,4, num[num3*8+3]);
//lc.setColumn(2,5, num[num3*8+2]);
//lc.setColumn(2,6, num[num3*8+1]);
//lc.setColumn(2,7, num[num3*8+0]);
// end of activation
while(counter != 4)
{
currentStateCLK = digitalRead(pinCLK);
if(currentStateCLK != previousStateCLK)
{
if (digitalRead(pinDT) != currentStateCLK)
{
counter --;// diminue la valeur du compteur
}else
{
counter ++;// sinon on l'augmente
}
Serial.print("Value: ");
Serial.println(counter);
}
previousStateCLK = currentStateCLK;
}
Serial.println("Back to 0");
}
}
previousStateCLK = currentStateCLK;
//delay(50);
//y --;
}
//}