joshi
Published © GPL3+

Settlers Of Catan Dice

Do you love playing Settlers of Catan? You'll love it even more with this Arduino Dice!

BeginnerFull instructions provided9,903

Things used in this project

Story

Read more

Code

Settlers of Catan Dice code

Arduino
Don't forget to include the Liquid Crystal library.
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int diceButton = 10;
int reply;

int count = 0;

long diceOne;
long diceTwo;

void setup() {
    lcd.begin(16, 2);
    pinMode(diceButton, INPUT);
    randomSeed(analogRead(0));
    lcd.setCursor(1, 0);
    lcd.print("Roll the dice!");
}

void buildUp() {
    lcd.clear();
    int countDelay = 220;
    int setColumn = 0;
    for (count = 0; count <= 16; count++) {
        lcd.setCursor(setColumn, 0);
        lcd.print(random(1, 7));
        lcd.setCursor(setColumn, 1);
        lcd.print(random(1, 7));
        delay(countDelay);
        countDelay -= 13;
        setColumn += 1;
    }
}

void loop() {
    diceButton = digitalRead(10);
    diceOne = random(1, 7);
    diceTwo = random(1, 7);

    if (diceButton == HIGH) {
        buildUp();
        lcd.clear();
        lcd.setCursor(7, 0);
        lcd.print(diceOne);
        lcd.setCursor(7, 1);
        lcd.print(diceTwo);

        if (diceOne + diceTwo == 7) {
            lcd.clear();
            lcd.setCursor(7, 0);
            lcd.print("7");
            lcd.setCursor(3, 1);
            lcd.print("The Robber");
        }
    }
}

Credits

joshi

joshi

0 projects • 21 followers

Comments