daniel_lawson9999

Daniel Lawson Crystal Ball

Oct 21st, 2015
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1.  
  2. #include<LiquidCrystal.h>
  3. LiquidCrystal lcd(12,11,5,4,3,2);
  4. const int switchPin = 6;
  5. int switchState = 0;
  6. int prevSwitchState = 0;
  7. int reply;
  8.  
  9.  
  10.  
  11. void setup()
  12. {
  13. lcd.begin(16,2);
  14.  
  15. pinMode(switchPin,INPUT);
  16.  
  17. lcd.print("ask the");
  18.  
  19. lcd.setCursor(0,1);
  20. lcd.print("Crystal Ball");
  21.  
  22. }
  23.  
  24. void loop()
  25. {
  26. switchState = digitalRead(switchPin);
  27. if (switchState != prevSwitchState)
  28. {
  29. if (switchState == LOW)
  30. {
  31. reply = random(8);
  32. lcd.clear();
  33. lcd.setCursor(0,0);
  34. lcd.print("The ball says:");
  35. lcd.setCursor(0,1);
  36.  
  37. switch(reply)
  38. {
  39. case 0:
  40. lcd.print("Yes");
  41. break;
  42. case 1:
  43. lcd.print("Most likely");
  44. break;
  45. case 2:
  46. lcd.print("Certainly");
  47. break;
  48. case 3:
  49. lcd.print("Outlook good");
  50. break;
  51. case 4:
  52. lcd.print("Unsure");
  53. break;
  54. case 5:
  55. lcd.print("Ask again");
  56. break;
  57. case 6:
  58. lcd.print("Doubtful");
  59. break;
  60. case 7:
  61. lcd.print("No");
  62. break;
  63. }
  64. }
  65. }
  66.  
  67. prevSwitchState = switchState;
  68. }
Advertisement
Add Comment
Please, Sign In to add comment