Hey guys I really need help with this code It is set up to have the 6 different dice from D&D there is a potentiometer that is set to change the number of dice that are rolled at once (Ex. i want to roll 4 six sided dice at one time) What do i need to add to make it so i can roll more then one die at a time? thanks for the help!!
#include <LiquidCrystal.h>
const int diceUpPin = 8;
const int rollPin = 9;
int pot = A0;
int die = 0;
int val = 0;
int theDice[] = {4, 6, 8, 10, 12, 20, 100};
int diceUpState = 0;
int rollState = 0;
int increment = 0;
int randomChance;
boolean rolled = false;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
pinMode(diceUpPin, INPUT);
pinMode(rollPin, INPUT);
intro();
}
void loop()
{
val = analogRead(pot);
die = map(val,0,1024,1,11);
diceUpState = digitalRead(diceUpPin);
rollState = digitalRead(rollPin);
rolled = false;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" Using ");
lcd.print(die);
lcd.print(" D");
lcd.print(theDice[increment]);
delay(250);
if(diceUpState == HIGH)
{
increment++;
if(increment > 6)
{
increment = 0;
}
}
if(rollState == HIGH) /
{
randomSeed(analogRead(A1));
randomChance = random(1,theDice[increment] + 1);
rolled = true;
}
if(rolled)
{
lcd.setCursor(0,1);
lcd.print("You rolled a ");
lcd.print(randomChance);
delay(2000);
}
}
void intro()
{
lcd.begin(16, 2);
lcd.print(" Welcome to D&D");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" By: Andrew Coe");
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Red button to");
lcd.setCursor(0,1);
lcd.print("switch dice");
delay(1750);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Green button to");
lcd.setCursor(0,1);
lcd.print("roll dice");
delay(1750);
}
Dice.ino (3.16 KB)