Guest User

Arduino Crystal Ball Code (C++)

a guest
Nov 19th, 2024
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | Source Code | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  4.  
  5. const int switchPin = 6;
  6. int switchState = 0;
  7. int prevSwitchState = 0;
  8. int reply;
  9.  
  10. void setup() {
  11.   lcd.begin(16, 2);
  12.  
  13.   pinMode(switchPin, INPUT);
  14.   lcd.print("Ask the");
  15.   lcd.setCursor(0, 1);
  16.   lcd.print("Crystal Ball");
  17. }
  18.  
  19. void loop() {
  20.   switchState = digitalRead(switchPin);
  21.  
  22.   if (switchState != prevSwitchState) {
  23.     if (switchState == LOW) {
  24.       reply = random(8);
  25.       lcd.clear();
  26.       lcd.setCursor(0, 0);
  27.       lcd.print("The ball says:");
  28.       lcd.setCursor(0, 1);
  29.  
  30.       switch (reply) {
  31.         case 0:
  32.           lcd.print("Yes");
  33.           break;
  34.         case 1:
  35.           lcd.print("Probably");
  36.           break;
  37.         case 2:
  38.           lcd.print("Certainly");
  39.           break;
  40.         case 3:
  41.           lcd.print("Quite Possibly");
  42.           break;
  43.         case 4:
  44.           lcd.print("Not So Sure");
  45.           break;
  46.         case 5:
  47.           lcd.print("Ask again");
  48.           break;
  49.         case 6:
  50.           lcd.print("No idea");
  51.           break;
  52.         case 7:
  53.           lcd.print("No");
  54.           break;
  55.       }
  56.     }
  57.   }
  58. }
  59.  
Tags: Arduino
Add Comment
Please, Sign In to add comment