#include <LedControl.h>
const int pinoBotao = 7; // Replace with the desired pin number
const int DIN = 12;
const int CS = 11;
const int CLK = 10;
const int rollDelay = 25;
const int maxRollSpeed = 1000;
LedControl lc = LedControl(DIN, CLK, CS, 4);
byte characters[][8] = {
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03},
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xC0, 0xC0},
{0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x00, 0x00},
{0x00, 0x00, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00},
{0xC0, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
{0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x03, 0x03},
{0xC0, 0xC0, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00},
{0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0xC0, 0xC0},
{0x03, 0x03, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00},
{0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00, 0x3C, 0x3C},
{0x3C, 0x3C, 0x00, 0x3C, 0x3C, 0x3C, 0x3C, 0x00}
};
int rollSpeed = 0;
bool rolando = false;
int lastPress = LOW;
//-------------------------------------------------------------------
void setup() {
for (int i = 0; i <4; i++)
{
lc.shutdown(i, false);
lc.setIntensity(i, 6);
lc.clearDisplay(i);
}
pinMode(pinoBotao, INPUT_PULLUP);
lastPress = digitalRead(pinoBotao);
}
//-------------------------------------------------------------------
void loop() {
int estadoBotao = digitalRead(pinoBotao);
if (estadoBotao == HIGH && lastPress == LOW) {
rolando = true;
rollSpeed = 0;
}
if (rollSpeed <= maxRollSpeed && rolando) {
int valorDado = random(1, 7);
//int valorDado = 6;
printByte(valorDado);
delay(rollDelay);
rollSpeed += rollDelay;
} else if (rolando) {
rolando = false;
}
lastPress = estadoBotao;
}
//-------------------------------------------------------------------
void printByte(int valorDado) {
switch (valorDado) {
case 1:
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, characters[1][i]);
lc.setRow(1, i, characters[2][i]);
lc.setRow(2, i, characters[6][i]);
lc.setRow(3, i, characters[5][i]);
}
break;
case 2:
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, characters[3][i]);
lc.setRow(1, i, characters[0][i]);
lc.setRow(2, i, characters[0][i]);
lc.setRow(3, i, characters[4][i]);
}
break;
case 3:
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, characters[7][i]);
lc.setRow(1, i, characters[2][i]);
lc.setRow(2, i, characters[6][i]);
lc.setRow(3, i, characters[8][i]);
}
break;
case 4:
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, characters[3][i]);
lc.setRow(1, i, characters[3][i]);
lc.setRow(2, i, characters[4][i]);
lc.setRow(3, i, characters[4][i]);
}
break;
case 5:
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, characters[7][i]);
lc.setRow(1, i, characters[9][i]);
lc.setRow(2, i, characters[10][i]);
lc.setRow(3, i, characters[8][i]);
}
break;
case 6:
for (int i = 0; i < 8; i++) {
lc.setRow(0, i, characters[11][i]);
lc.setRow(1, i, characters[11][i]);
lc.setRow(2, i, characters[12][i]);
lc.setRow(3, i, characters[12][i]);
}
break;
default:
break;
}
}