My idea to roll 2 dice was to repeat the initial code twice , just changing the output to tm.display(0,1) and then tm.display(3,1), but no joy.
Below code just shows number twice. I want to different random rolls, by delaying the same repeated code with just 2 quick button presses.
#include <TM1637.h>
//declare pins
int CLK = D2;
int DIO = D3;
int DIC = D8;
int buttonState = 0;
int randNum = 0;
TM1637 tm(CLK, DIO);
void setup() {
// put your setup code here, to run once:
//define input ouptut pins
pinMode(DIC, INPUT);
//initialize serial comm @ 9600
Serial.begin(115200);
//initializes the pseudo-random number generator
randomSeed(analogRead(0));
//initialize TM1637 seven segment display
tm.init();
//set brightness; 0-7
tm.set(2);
tm.init();
}
void loop() {
//read button
buttonState = digitalRead(DIC);
//decision taking
if (buttonState == LOW) {
randNum = throwDice(); //call thowDice function
Serial.println(randNum); //serial print for debugging
//switch case
// tm.display(position, character);
switch (randNum) {
case 1:
tm.display(0, 1);
tm.display(3, 1);
delay(5000);
randNum = 0;
break;
case 2:
tm.display(0, 2);
tm.display(3, 2);
delay(5000);
randNum = 0;
break;
case 3:
tm.display(0, 3);
tm.display(3, 3);
delay(5000);
randNum = 0;
break;
case 4:
tm.display(0, 4);
tm.display(3, 4);
delay(5000);
randNum = 0;
break;
case 5:
tm.display(0, 5);
tm.display(3, 5);
delay(5000);
randNum = 0;
break;
case 6:
tm.display(0, 6);
tm.display(3, 6);
randNum = 0;
break;
}
buttonState = 0; //rule out false triggering
randNum = 0; //clear last digit
}
//waits for swith to be pressed
else {
tm.display(0, 0);
tm.point(1);
tm.display(3, 0);
buttonState = 0;
randNum = 0;
}
}
//function to generate randowm number
int throwDice() {
int numRand = random(1, 7); // min=1 and max= max-1, 6
return numRand;
}