Devices & Components
Arduino Uno Rev3
Jumper wires (generic)
Pushbutton switch 12mm
Breadboard (generic)
Rotary potentiometer (generic)
USB-A to B Cable
Standard LCD - 16x2 White on Blue
Project description
Code
The code
arduino
1 2#include <LiquidCrystal.h> 3long randNumber; 4int Led = 13; //define LED port 5int Shock = 2; //define shock port 6int val;//define digital variable val 7// initialize the library with the numbers of the interface pins 8LiquidCrystal lcd(7, 8, 9, 10, 11, 12 ); 9byte customChar[] = { 10 B00000, 11 B00000, 12 B11111, 13 B11001, 14 B10101, 15 B10011, 16 B11111, 17 B00000 18}; 19void setup() 20{ 21 22 lcd.begin(16, 2); 23 lcd.createChar(0, customChar); 24 lcd.home(); 25 pinMode(Led, OUTPUT); //define LED as a output port 26 randomSeed(analogRead(0)); 27 pinMode(Shock, INPUT); //define shock sensor as a output port 28 lcd.write(byte( 0)); 29 lcd.print("Digital dice"); 30 lcd.write(byte( 0)); 31 delay(1000); 32} 33 34void loop() 35{ 36 37 val = digitalRead(Shock); //read the value of the digital interface 3 assigned to val 38 if (val == LOW) //when the shock sensor have signal do the following 39 { 40 lcd.clear(); 41 lcd.print("Rolling dice..."); 42 delay(4000); 43 lcd.clear(); 44 lcd.setCursor(0, 0); 45 randNumber = random(1,7); 46 lcd.print("Dice 1 = "); 47 lcd.print(randNumber); 48 49 lcd.setCursor(0, 1); 50 randNumber = random(1,7); 51 lcd.print("Dice 2 = "); 52 lcd.print(randNumber); 53 54 } 55 56 delay(150); 57}
The code
arduino
1 2#include <LiquidCrystal.h> 3long randNumber; 4int Led = 13; //define LED port 5int Shock = 2; //define shock port 6int val;//define digital variable val 7// initialize the library with the numbers of the interface pins 8LiquidCrystal lcd(7, 8, 9, 10, 11, 12 ); 9byte customChar[] = { 10 B00000, 11 B00000, 12 B11111, 13 B11001, 14 B10101, 15 B10011, 16 B11111, 17 B00000 18}; 19void setup() 20{ 21 22 lcd.begin(16, 2); 23 lcd.createChar(0, customChar); 24 lcd.home(); 25 pinMode(Led, OUTPUT); //define LED as a output port 26 randomSeed(analogRead(0)); 27 pinMode(Shock, INPUT); //define shock sensor as a output port 28 lcd.write(byte( 0)); 29 lcd.print("Digital dice"); 30 lcd.write(byte( 0)); 31 delay(1000); 32} 33 34void loop() 35{ 36 37 val = digitalRead(Shock); //read the value of the digital interface 3 assigned to val 38 if (val == LOW) //when the shock sensor have signal do the following 39 { 40 lcd.clear(); 41 lcd.print("Rolling dice..."); 42 delay(4000); 43 lcd.clear(); 44 lcd.setCursor(0, 0); 45 randNumber = random(1,7); 46 lcd.print("Dice 1 = "); 47 lcd.print(randNumber); 48 49 lcd.setCursor(0, 1); 50 randNumber = random(1,7); 51 lcd.print("Dice 2 = "); 52 lcd.print(randNumber); 53 54 } 55 56 delay(150); 57}
Downloadable files
The schematic
The schematic

Comments
Only logged in users can leave comments