Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Magic 8 Ball
- learnelectronics
- 25 Jun 2018
- www.youtube.com/c/learnelectronics
- email: [email protected]
- */
- #include <LiquidCrystal.h> // include the library code:
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- bool myswitch = 1; // create Boolian varibale for switch
- void setup() {
- lcd.begin(16, 2); // set up the LCD's number of columns and rows:
- pinMode(8,INPUT_PULLUP); //set pin 8 as input with internal pullup
- }
- void doit(){ //declare function for when switch is activated
- randomSeed(analogRead(0)); //seed random num generator
- int randNumber = random(5); //get random number between 0 and 5
- lcd.setCursor(0, 1); //reset cursor
- lcd.print(" "); //clear display
- lcd.setCursor(0, 1); //reset cursor
- switch (randNumber) { //switch case on random number
- case 0: //send answer to lcd
- lcd.print("YES!");
- break;
- case 1:
- lcd.print("No");
- break;
- case 2:
- lcd.print("Maybe");
- break;
- case 3:
- lcd.print("Ask me later");
- break;
- case 4:
- lcd.print("Answer Unclear");
- break;
- case 5:
- lcd.print("Just order pizza");
- break;
- }
- }
- void loop() {
- myswitch = digitalRead(8); //read pin 8 and send result to variable
- if (myswitch == 0){ //if the pin is low
- doit(); //call function doit
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement