For that part i will be using my code from the dices i have made with it and here is the code for it:
/*-----( Import needed libraries )-----*/
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h> // F Malpartida's NewLiquidCrystal library
//Download: https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads
// Move original LiquidCrystal library elsewhere, copy this in it's place
/*-----( Declare Constants )-----*/
#define I2C_ADDR 0x27 // Define I2C Address for the PCF8574T
//---(Following are the PCF8574 pin assignments to LCD connections )----
// This are different than earlier/different I2C LCD displays
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define LED_OFF 1
#define LED_ON 0
const int buttonPin = 2;
int buttonState = 0;
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
// Project 15 - Creating an Electronic Die
void setup()
{
Serial.begin(9600);
lcd.begin (20,4); // initialize the lcd
// Switch on the backlight
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(LED_ON);
randomSeed(analogRead(0)); // seed the random number generator
for ( int z = 1 ; z < 7 ; z++ ) // LEDs on pins 1-6 are output
{
pinMode(z, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
}
}
void loop()
{
int ok = 0;
buttonState = digitalRead(buttonPin);
while (buttonState == HIGH) {
buttonState = digitalRead(buttonPin);
Serial.println(buttonState);
ok = 1;
delay (50);
}
if (ok == 1) {
int rr;
int r;
r = random(1, 7); // get a random number from 1 to 6
rr = random(1, 7);
// Print our characters on the LCD
lcd.backlight(); //Backlight ON if under program control
lcd.setCursor(1,0); //Start at character 4 on line 0
lcd.print("You rolled:");
lcd.print(r);
lcd.print ("+");
lcd.print(rr);
lcd.print ("=");
lcd.print(r+rr);
lcd.print(" ");
switch (r) {
case 1:
lcd.setCursor(4,1);
lcd.print(" ");
lcd.setCursor(4,2);
lcd.print(" o ");
lcd.setCursor(4,3);
lcd.print(" ");
break;
case 2:
lcd.setCursor(4,1);
lcd.print(" o");
lcd.setCursor(4,2);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print("o ");
break;
case 3:
lcd.setCursor(4,1);
lcd.print(" o");
lcd.setCursor(4,2);
lcd.print(" o ");
lcd.setCursor(4,3);
lcd.print("o ");
break;
case 4:
lcd.setCursor(4,1);
lcd.print("o o");
lcd.setCursor(4,2);
lcd.print(" ");
lcd.setCursor(4,3);
lcd.print("o o");
break;
case 5:
lcd.setCursor(4,1);
lcd.print("o o");
lcd.setCursor(4,2);
lcd.print(" o ");
lcd.setCursor(4,3);
lcd.print("o o");
break;
case 6:
lcd.setCursor(4,1);
lcd.print("o o");
lcd.setCursor(4,2);
lcd.print("o o");
lcd.setCursor(4,3);
lcd.print("o o");
break;
}
switch (rr) {
case 1:
lcd.setCursor(13,1);
lcd.print(" ");
lcd.setCursor(13,2);
lcd.print(" o ");
lcd.setCursor(13,3);
lcd.print(" ");
break;
case 2:
lcd.setCursor(13,1);
lcd.print(" o");
lcd.setCursor(13,2);
lcd.print(" ");
lcd.setCursor(13,3);
lcd.print("o ");
break;
case 3:
lcd.setCursor(13,1);
lcd.print(" o");
lcd.setCursor(13,2);
lcd.print(" o ");
lcd.setCursor(13,3);
lcd.print("o ");
break;
case 4:
lcd.setCursor(13,1);
lcd.print("o o");
lcd.setCursor(13,2);
lcd.print(" ");
lcd.setCursor(13,3);
lcd.print("o o");
break;
case 5:
lcd.setCursor(13,1);
lcd.print("o o");
lcd.setCursor(13,2);
lcd.print(" o ");
lcd.setCursor(13,3);
lcd.print("o o");
break;
case 6:
lcd.setCursor(13,1);
lcd.print("o o");
lcd.setCursor(13,2);
lcd.print("o o");
lcd.setCursor(13,3);
lcd.print("o o");
break;
}
}
}
I will take some from it and put it in the new one and just change the "lcd.print()" to match it with what i wrote earlier.
-Cister