Advertisement
tarbear123

Untitled

Feb 4th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd( 8, 9, 4, 5, 6, 7);
  3. int randNumber = 0;
  4. #define btnRIGHT 0
  5. #define btnUP 1
  6. #define btnDOWN 2
  7. #define btnLEFT 3
  8. #define btnSELECT 4
  9. #define btnNONE 5
  10. int adc_key_in = 0;
  11. int lcd_key = 0;
  12.  
  13. // read the buttons
  14.  
  15. int read_LCD_buttons()
  16. {
  17. adc_key_in = analogRead(0); // read the value from the sensor
  18. // my buttons when read are centered at these valies: 0, 144, 329, 504, 741
  19. // we add approx 50 to those values and check to see if we are close
  20. //if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed reasons since it will be the most likely result
  21. // For V1.1 us this threshold
  22.  
  23. if (adc_key_in > 1000) return btnNONE;
  24. /*
  25. if (adc_key_in < 50) return btnRIGHT;
  26. if (adc_key_in < 250) return btnUP;
  27. if (adc_key_in < 450) return btnDOWN;
  28. if (adc_key_in < 650) return btnLEFT;
  29. if (adc_key_in < 850) return btnSELECT;
  30. */
  31.  
  32. // For V1.0 comment the other threshold and use the one below:
  33. if (adc_key_in < 50) return btnRIGHT;
  34. if (adc_key_in < 195) return btnUP;
  35. if (adc_key_in < 380) return btnDOWN;
  36. if (adc_key_in < 555) return btnLEFT;
  37. if (adc_key_in < 790) return btnSELECT;
  38.  
  39.  
  40. return btnNONE; // when all others fail, return this...
  41. }
  42.  
  43.  
  44. void setup() {
  45.  
  46. lcd.begin(16, 2); // start the library
  47. lcd.setCursor(0, 0);
  48. lcd.print("press select to dice"); // print a simple message
  49. randomSeed (analogRead (1));
  50. }
  51.  
  52.  
  53. void loop() {
  54. int diceOne = random (1, 7);
  55. int diceTwo = random (1, 5);
  56.  
  57. lcd_key = read_LCD_buttons(); // read the buttons
  58.  
  59. if (lcd_key == btnSELECT) {
  60. lcd.clear();
  61. lcd.setCursor(1,0);
  62. lcd.print(diceOne);
  63. lcd.setCursor(7,0);
  64. lcd.print(diceTwo );
  65.  
  66. analogRead (lcd_key == btnSELECT);
  67. delay (50);
  68. analogRead (lcd_key == btnSELECT);
  69. delay (50);
  70.  
  71.  
  72.  
  73. if (diceTwo == 1) {
  74. lcd.setCursor(7,0);
  75. lcd.print (diceTwo);
  76. lcd.setCursor (2,1);
  77. lcd.print ("BRIDGEDATTACK");
  78. }
  79. if (diceTwo == 2) {
  80. lcd.setCursor(7,0);
  81. lcd.print (diceTwo);
  82. lcd.setCursor (6,1);
  83. lcd.print ("TRADE");
  84. }
  85. if (diceTwo == 3) {
  86. lcd.setCursor(7,0);
  87. lcd.print (diceTwo);
  88. lcd.setCursor (6,1);
  89. lcd.print ("harp");
  90. }
  91. if (diceTwo == 4) {
  92. lcd.setCursor(7,0);
  93. lcd.print (diceTwo);
  94. lcd.setCursor (6,1);
  95. lcd.print ("wheat");
  96. }
  97. if (diceTwo == 5) {
  98. lcd.setCursor(7,0);
  99. lcd.print (diceTwo);
  100. lcd.setCursor (4,1);
  101. lcd.print ("question");
  102. }
  103. if (diceTwo == 1 > 3) {
  104. lcd.clear();
  105. lcd.setCursor(7, 0);
  106. lcd.print("2,3,4,5");
  107. }
  108. if (diceTwo == 2 > 2) {
  109. lcd.clear();
  110. lcd.setCursor(7, 0);
  111. lcd.print("3,4,5");
  112. }
  113. if (diceTwo == 3 > 3) {
  114. lcd.clear();
  115. lcd.setCursor(7, 0);
  116. lcd.print("4,5");
  117. }
  118. if (diceTwo == (4 > 2)) {
  119. lcd.clear();
  120. lcd.setCursor(7,0);
  121. lcd.print("5");
  122. }
  123. }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement