Hello,
I am trying to make a digital dice for my project in school. I am having troubles with the programming, I don't really know how to write code and I am not a programmer and my school isn't really helpful with this.
I took inspiration from a post on the Arduino website (Arduino Digital Dice | Arduino Project Hub) where someone already made the project that I'm trying to make. I connected the LCD and the Arduino UNO the same way that is shown on the schematic (I hope its connected correctly) as well as the button and potentiometer. I just used a smaller breadboard but as far as I know that shouldn't change anything.
The code that I used was the same as the one from the already made project. The problem is that when I upload the code to the Arduino, it doesn't actually roll any numbers, it just says that its rolling and thats it.
In the code I need it to roll or randomly generate numbers from 1 to 12. If possible I would like to make it so that it has different modes where if for example if I pressed the button twice it would change the mode to generate numbers from 1 to 6.
I am now asking for someone to help me out atleast a little bit, if someone could tell me if I connected something incorrectly or if the code isn't good or if there is a better code I could use here.
If its any help to know I am using an Arduino UNO R3, LCD display (Module no: DEM 16216 SYH-PY), a normal pushbutton and a 10k potentiometer.
Here are the schematics and some pictures;
It won't allow me to upload more than 3 pictures so if the pictures don't look too good maybe I can reply with a picture where you can see the connections better if that is an option...
This the code that I used for the programing;
#include <LiquidCrystal.h>
long randNumber;
int Led = 13; //define LED port
int Shock = 2; //define shock port
int val;//define digital variable val
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12 );
byte customChar[] = {
B00000,
B00000,
B11111,
B11001,
B10101,
B10011,
B11111,
B00000
};
void setup()
{
lcd.begin(16, 2);
lcd.createChar(0, customChar);
lcd.home();
pinMode(Led, OUTPUT); //define LED as a output port
randomSeed(analogRead(0));
pinMode(Shock, INPUT); //define shock sensor as a output port
lcd.write(byte( 0));
lcd.print("Digital dice");
lcd.write(byte( 0));
delay(1000);
}
void loop()
{
val = digitalRead(Shock); //read the value of the digital interface 3 assigned to val
if (val == LOW) //when the shock sensor have signal do the following
{
lcd.clear();
lcd.print("Rolling dice...");
delay(4000);
lcd.clear();
lcd.setCursor(0, 0);
randNumber = random(1,7);
lcd.print("Dice 1 = ");
lcd.print(randNumber);
lcd.setCursor(0, 1);
randNumber = random(1,7);
lcd.print("Dice 2 = ");
lcd.print(randNumber);
}
delay(150);
}
I appreciate anyone that will help in any way!