-
Notifications
You must be signed in to change notification settings - Fork 0
/
dices.ino
84 lines (77 loc) · 1.73 KB
/
dices.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//Dices!!! for Arduino
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
const int d6 = 7;
const int d8 = 8;
const int d20 = 9;
const int timer = 13;
int dice;
bool timerGo = false;
int timeLeft = 60;
void setup() {
//LCD
lcd.begin(16,2);
lcd.print("Dices!!!");
lcd.setCursor(0,1);
lcd.print("Make a roll.");
//Dice buttons
pinMode(d6, INPUT);
pinMode(d8, INPUT);
pinMode(d20, INPUT);
pinMode(timer, INPUT);
}
void loop() {
if(timerGo == true){
if(timeLeft == 0) {
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your timer is finished.");
lcd.setCursor(0,1);
lcd.print("Make a roll!");
timerGo = false;
timeLeft = 60;
}
else {
timeLeft--;
lcd.setCursor(0,1);
lcd.print(timeLeft);
lcd.print(" seconds");
delay(1000);
}
}
else {
if(digitalRead(d6) == HIGH || digitalRead(d8) == HIGH || digitalRead(d20) == HIGH){
if(digitalRead(d6) == HIGH) {
dice = 6;
}
else if(digitalRead(d8) == HIGH) {
dice = 8;
}
else if(digitalRead(d20) == HIGH) {
dice = 20;
}
int roll = random(dice)+1;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Your D");
lcd.print(dice);
lcd.print(" roll:");
lcd.setCursor(0,1);
lcd.print(roll);
delay(100);
}
else if(digitalRead(timer) == HIGH) {
timerGo = true;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Time left:");
lcd.setCursor(0,1);
lcd.print(timeLeft);
lcd.print(" seconds");
delay(1000);
}
else {
delay(100);
}
}
}