/* The circuit: * LCD RS pin to digital pin 12 * LCD Enable pin to digital pin 11 * LCD D4 pin to digital pin 5 * LCD D5 pin to digital pin 4 * LCD D6 pin to digital pin 3 * LCD D7 pin to digital pin 2 * 10K resistor: * ends to +5V and ground * wiper to LCD VO pin (pin 3) */ // include the library code: #include #define countof(array) ( sizeof(array) / sizeof(*(array)) ) // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 2); int ledPin = 13; // choose the pin for the LED int inPin = 6; // choose the input pin (for a pushbutton) int val = 0; // variable for reading the pin status int pos1 = 1; int pos2 = 0; int x=0; int b = 0; int y = 0; int tv = 0; int tv2 = 0; long previousMillis = 0; // will store last time LED was updated long interval = 1100; // interval at which to blink (milliseconds) char *msgs1[] = {"A promotion is","You will soon","Laughter is the","Live long and", "Laugh hard and", "Eat well and", "A creative ","Someone", "A merry heart","Seize the day.","You are","Wealth is","Happy times","I see robots","Smile and you","Luck will soon"}; char *msgs2[] = {"coming soon.","be happy.","best medicine.","prosper.", "laugh often.", "make merry.", "mind is yours.","loves you.","is good.", " ","very lucky!", "soon yours.", "are ahead.", "in your future.","will be rich.","follow you."}; char *msgs3[] = {"!","@","#","$", "%", "&", "* ","@", "?","="}; char *msgs4[] = {"1","2","3","4", "5", "6", "7","8", "9","10","11","12","14","15","16","17","18","19","20"}; int NUM_MSGS = 11; int NUM_MSGS2 = 19; int i=0; char my_str[100]; void setup() { pinMode(ledPin, OUTPUT); // declare LED as output pinMode(inPin, INPUT); // declare pushbutton as input pinMode(0,INPUT); randomSeed(analogRead(0)); // set up the LCD's number of rows and columns: lcd.begin(16, 2); } void loop() { digitalWrite(13, HIGH); lcd.clear(); lcd.print("Fortune Teller"); lcd.setCursor(0, 1); lcd.print("Robot 3000"); delay(2000); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Thinking"); for (int i=0; i<3; i++) { lcd.print('.'); delay(400); } lcd.setCursor(0, 0); lcd.clear(); for (int i=0; i<9; i++) { pos2=pos2+1; pos1=pos1+i; int pick = random(NUM_MSGS); int randy = random(1,10); char* msg3 = msgs3[randy]; lcd.print(msg3); delay(300); if (pos2>= 2) pos2=0; } lcd.clear(); lcd.setCursor(0, 0); lcd.print("Your"); lcd.setCursor(0, 1); lcd.print("fortune is"); delay(1200); for (int i=0; i<3; i++) { lcd.print('.'); delay(300); } for (int positionCounter = 0; positionCounter < 20; positionCounter++) { lcd.scrollDisplayLeft(); // scroll one position left: delay(50); // wait a bit: } lcd.clear(); //pick a random message from the array int rind= random(1,21)-10; if (rind == x) { rind=rind+1; } else { rind= random(rind); } x=rind; int randNumber= random(1, countof(msgs1)); char* msg1 = msgs1[randNumber ]; char* msg2 = msgs2[randNumber ]; lcd.print(msg1); lcd.setCursor(0, 1); lcd.print(msg2); delay(2500); lcd.clear(); int pick2 = random(NUM_MSGS2); char* msg4 = msgs4[pick2]; lcd.setCursor(1, 0); strcpy(my_str, "number is "); strcat(my_str, msg4); strcat(my_str, "."); lcd.print("Your lucky"); lcd.setCursor(0, 1); lcd.print(my_str); delay(1200); for (int i=0; i<3; i++){ lcd.print('.'); delay(300); } delay(300); for (int positionCounter = 0; positionCounter < 20; positionCounter++) { lcd.scrollDisplayLeft(); // scroll one position left: delay(50); // wait a bit: } lcd.clear(); lcd.setCursor(0, 0); val = digitalRead(inPin); // read input value animation2(); } void animation2() { digitalWrite(13, HIGH); do { val = digitalRead(inPin); // read input value if (val == HIGH) { // check if the input is HIGH (button released) b = 0; } else { b = 1; y=0; tv=0; tv2=0; } if (millis() - previousMillis > interval) { previousMillis = millis(); // remember the last time we printed tv = tv +1; tv2=tv2+1; if (tv == 1) { lcd.clear(); lcd.print("Fortune Teller"); } if (tv == 2) { lcd.setCursor(0, 1); lcd.print("Robot 3000"); } if (tv == 3 && tv2 !=9 && tv2 !=10) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Push the button"); } if (tv == 4 && tv2 !=9 && tv2 !=10) { lcd.setCursor(0, 1); lcd.print("for a fortune!"); } if (tv2==7) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Your fortune"); } if (tv2==8) { lcd.setCursor(0, 1); lcd.print("awaits you."); tv=0; tv2=0; } } } while (b==0); }