I had the dice code, but reset and forgot to back the code up, now I need help creating the code again, I can't get the select button to proceed to the loop when pressed here's what I have so far:

#include <LiquidCrystal.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

//used for later
String line2 = "Press Select to roll"; // Scrolling line

// define some values used by the panel and buttons
int lcd_key     = 0;
int adc_key_in  = 0;
#define btnRIGHT  0
#define btnUP     1
#define btnDOWN   2
#define btnLEFT   3
#define btnSELECT 4
#define btnNONE   5

// read the buttons
int read_LCD_buttons()
 adc_key_in = analogRead(0);      // read the value from the sensor

 // For V1.0 comment the other threshold and use the one below:

 if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
 // For V1.1 us this threshold
 if (adc_key_in < 50)   return btnRIGHT;
 if (adc_key_in < 195)  return btnUP;
 if (adc_key_in < 380)  return btnDOWN;
 if (adc_key_in < 555)  return btnLEFT;
 if (adc_key_in < 790)  return btnSELECT;

 return btnNONE;  // when all others fail, return this...

void setup() {
 lcd.begin(16, 2);              // start the library
 lcd.print ("Catan Dice");
 lcd.print("Press Select to roll");

void loop() {
//local varables 
int buttonState = read_LCD_buttons(); // read the button pad
int lastButtonState = btnNONE; // previous state of the button

int DiceOne = random(1,7);
int DiceTwo = random(1,7);

  if (buttonState != lastButtonState) {
  // if the state has changed, increment the counter
  if (buttonState == HIGH) {
  // if the current state is HIGH then the button went from off to on:

if (btnState == btnSELECT)
  lcd.setCursor (0,4);


lastButtonState = buttonState;


can anyone help me plz

  • I see you have edited the question and completely changed the sketch. What is the error message this sketch is giving you? – VE7JRO Apr 20 '18 at 23:40

You know that LCD shield buttons are usually multiplexed to the analog pin A0? If I've googled correct schematics, this applies to this one too. Therefore no pin change interrupts nor external interrupts can be used.

Maybe analog comparator module with correct threshold.

  • can someone help me with my project, the problem is up top – taran Apr 19 '18 at 21:32

You are including the AnalogDebounce.h library but you are not using any code in the loop() to poll/refresh which button (if any) is pressed. Have a look at the "BasicUse" example here: https://github.com/MatCat/AnalogDebounce. There is also a library for the DFRkeypad: https://github.com/DFRobot/LCD-KeyPad-Shield. My first suggestion is to write a very simple sketch using a library that works with your keypad so yo can verify the buttons are working as intended.

There is a line of code in your sketch that makes absolutely no sense to me: if (diceOne + diceTwo == 5, 4, 3, 2, 6 ). I don't think you can compare dice 1 + 2 to a comma separated list of integers. Try this: if((diceOne + diceTwo > 1) && (diceOne + diceTwo < 7))

  • when I try and upload the LCD keypad- shield or the AnalogDebounce to the Arduino, it says error compiling, plz help – taran Apr 20 '18 at 22:05
  • Update your question with the code that will not compile and the error message. – VE7JRO Apr 20 '18 at 22:14
  • Arduino: 1.8.5 (Windows Store (Windows 10), Board: "Arduino/Genuino Uno" C:\Users\taran\Documents\Arduino\sketch_apr20b\sketch_apr20b.ino:1:23: fatal error: DFRkeypad.h: No such file or directory #include "DFRkeypad.h" ^ compilation terminated. exit status 1 Error compiling for board Arduino/Genuino Uno. – taran Apr 20 '18 at 22:33
  • It looks like you have not installed the DFRkeypad library from Github. – VE7JRO Apr 20 '18 at 22:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.