Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd( 8, 9, 4, 5, 6, 7);
- int randNumber = 0;
- #define btnRIGHT 0
- #define btnUP 1
- #define btnDOWN 2
- #define btnLEFT 3
- #define btnSELECT 4
- #define btnNONE 5
- int adc_key_in = 0;
- int lcd_key = 0;
- // read the buttons
- int read_LCD_buttons()
- {
- adc_key_in = analogRead(0); // read the value from the sensor
- // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
- // we add approx 50 to those values and check to see if we are close
- //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 > 1000) return btnNONE;
- /*
- if (adc_key_in < 50) return btnRIGHT;
- if (adc_key_in < 250) return btnUP;
- if (adc_key_in < 450) return btnDOWN;
- if (adc_key_in < 650) return btnLEFT;
- if (adc_key_in < 850) return btnSELECT;
- */
- // For V1.0 comment the other threshold and use the one below:
- 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.setCursor(0, 0);
- lcd.print("press select to dice"); // print a simple message
- randomSeed (analogRead (1));
- }
- void loop() {
- int diceOne = random (1, 7);
- int diceTwo = random (1, 5);
- lcd_key = read_LCD_buttons(); // read the buttons
- if (lcd_key == btnSELECT) {
- lcd.clear();
- lcd.setCursor(1,0);
- lcd.print(diceOne);
- lcd.setCursor(7,0);
- lcd.print(diceTwo );
- analogRead (lcd_key == btnSELECT);
- delay (50);
- analogRead (lcd_key == btnSELECT);
- delay (50);
- if (diceTwo == 1) {
- lcd.setCursor(7,0);
- lcd.print (diceTwo);
- lcd.setCursor (2,1);
- lcd.print ("BRIDGEDATTACK");
- }
- if (diceTwo == 2) {
- lcd.setCursor(7,0);
- lcd.print (diceTwo);
- lcd.setCursor (6,1);
- lcd.print ("TRADE");
- }
- if (diceTwo == 3) {
- lcd.setCursor(7,0);
- lcd.print (diceTwo);
- lcd.setCursor (6,1);
- lcd.print ("harp");
- }
- if (diceTwo == 4) {
- lcd.setCursor(7,0);
- lcd.print (diceTwo);
- lcd.setCursor (6,1);
- lcd.print ("wheat");
- }
- if (diceTwo == 5) {
- lcd.setCursor(7,0);
- lcd.print (diceTwo);
- lcd.setCursor (4,1);
- lcd.print ("question");
- }
- if (diceTwo == 1 > 3) {
- lcd.clear();
- lcd.setCursor(7, 0);
- lcd.print("2,3,4,5");
- }
- if (diceTwo == 2 > 2) {
- lcd.clear();
- lcd.setCursor(7, 0);
- lcd.print("3,4,5");
- }
- if (diceTwo == 3 > 3) {
- lcd.clear();
- lcd.setCursor(7, 0);
- lcd.print("4,5");
- }
- if (diceTwo == (4 > 2)) {
- lcd.clear();
- lcd.setCursor(7,0);
- lcd.print("5");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement