1#include <LiquidCrystal.h>
2LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
3
4int diceButton = 10;
5int reply;
6
7int count = 0;
8
9long diceOne;
10long diceTwo;
11
12void setup() {
13 lcd.begin(16, 2);
14 pinMode(diceButton, INPUT);
15 randomSeed(analogRead(0));
16 lcd.setCursor(1, 0);
17 lcd.print("Roll the dice!");
18}
19
20void buildUp() {
21 lcd.clear();
22 int countDelay = 220;
23 int setColumn = 0;
24 for (count = 0; count <= 16; count++) {
25 lcd.setCursor(setColumn, 0);
26 lcd.print(random(1, 7));
27 lcd.setCursor(setColumn, 1);
28 lcd.print(random(1, 7));
29 delay(countDelay);
30 countDelay -= 13;
31 setColumn += 1;
32 }
33}
34
35void loop() {
36 diceButton = digitalRead(10);
37 diceOne = random(1, 7);
38 diceTwo = random(1, 7);
39
40 if (diceButton == HIGH) {
41 buildUp();
42 lcd.clear();
43 lcd.setCursor(7, 0);
44 lcd.print(diceOne);
45 lcd.setCursor(7, 1);
46 lcd.print(diceTwo);
47
48 if (diceOne + diceTwo == 7) {
49 lcd.clear();
50 lcd.setCursor(7, 0);
51 lcd.print("7");
52 lcd.setCursor(3, 1);
53 lcd.print("The Robber");
54 }
55 }
56}