The Arduino projects book has an exercise on how to show text on the LCD screen. It's in project 11 and its called Crystal Ball. I'm going to use this as a base for my mini project and final project and learn how to connect everything properly. I still need to figure out how to generate random text via the code and how to make the two button options I want.
Code Used:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int switchPin = 6;
int switchState = 0;
int prevSwitchState = 0;
int reply;
void setup(){
lcd.begin(16, 2);
pinMode(switchPin, INPUT);
lcd.print("Ask the");
lcd.setCursor(0, 1);
lcd.print("Crystal Ball!");
}
void loop(){
switchState = digitalRead(switchPin);
if(switchState != prevSwitchState){
if(switchState == LOW){
reply = random(8);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("The ball says:");
lcd.setCursor(0, 1);
switch(reply){
case 0:
lcd.print("Yes");
break;
case 1:
lcd.print("Most Likely");
break;
case 2:
lcd.print("Certainly");
break;
case 3:
lcd.print("Outlook Good");
break;
case 4:
lcd.print("Unsure");
break;
case 5:
lcd.print("Ask Again");
break;
case 6:
lcd.print("Doubtful");
break;
case 7:
lcd.print("No");
break;
}
}
}
prevSwitchState = switchState;
}
No comments:
Post a Comment