Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the library code:
- #include <LiquidCrystal.h>
- // initialize the library by associating any needed LCD interface pin
- // with the arduino pin number it is connected to
- const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- int positiveSize = 3;
- int negativeSize = 3;
- String positive[3] = {"You will make a new friend.", "You will discover something new.", "You will get a good grade."};
- String negative[3] = {"You will forget something.", "Your next train will be delayed.", "You will get a bad grade."};
- int sensorPin = A0;
- void setup() {
- Serial.begin(9600);
- pinMode(sensorPin, INPUT);
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD
- }
- void loop() {
- int sensorValue = analogRead(sensorPin)-825;
- Serial.println(sensorValue);
- Serial.println(sensorValue > 0);
- String message;
- if (sensorValue > 0) {
- int index = random(negativeSize);
- message = negative[index];
- } else {
- int index = random(positiveSize);
- message = positive[index];
- }
- Serial.println(message);
- lcd.clear();
- stringToLCD(message);
- // to move it offscreen left:
- // for (int positionCounter = 0; positionCounter < sizeof(message); positionCounter++) {
- // // scroll one position left:
- // lcd.scrollDisplayLeft();
- // // wait a bit:
- // delay(300);
- // }
- delay(2000);
- }
- void stringToLCD(String stringIn) {
- int lineCount = 0;
- int lineNumber = 0;
- byte stillProcessing = 1;
- byte charCount = 1;
- lcd.clear();
- lcd.setCursor(0,0);
- while(stillProcessing) {
- if (++lineCount > 16) { // have we printed 20 characters yet (+1 for the logic)
- lineNumber += 1;
- lcd.setCursor(0,lineNumber); // move cursor down
- lineCount = 1;
- }
- lcd.print(stringIn[charCount - 1]);
- if (!stringIn[charCount]) { // no more chars to process?
- stillProcessing = 0;
- }
- charCount += 1;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment