Guest User

Untitled

a guest
Mar 23rd, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1.  
  2. // include the library code:
  3. #include <LiquidCrystal.h>
  4.  
  5. // initialize the library by associating any needed LCD interface pin
  6. // with the arduino pin number it is connected to
  7. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  8. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  9. int positiveSize = 3;
  10. int negativeSize = 3;
  11. String positive[3] = {"You will make a new friend.", "You will discover something new.", "You will get a good grade."};
  12. String negative[3] = {"You will forget something.", "Your next train will be delayed.", "You will get a bad grade."};
  13.  
  14. int sensorPin = A0;
  15.  
  16. void setup() {
  17. Serial.begin(9600);
  18. pinMode(sensorPin, INPUT);
  19. // set up the LCD's number of columns and rows:
  20. lcd.begin(16, 2);
  21. // Print a message to the LCD
  22.  
  23. }
  24.  
  25. void loop() {
  26.  
  27. int sensorValue = analogRead(sensorPin)-825;
  28. Serial.println(sensorValue);
  29. Serial.println(sensorValue > 0);
  30.  
  31. String message;
  32. if (sensorValue > 0) {
  33. int index = random(negativeSize);
  34. message = negative[index];
  35. } else {
  36. int index = random(positiveSize);
  37. message = positive[index];
  38. }
  39. Serial.println(message);
  40.  
  41. lcd.clear();
  42. stringToLCD(message);
  43.  
  44.  
  45. // to move it offscreen left:
  46. // for (int positionCounter = 0; positionCounter < sizeof(message); positionCounter++) {
  47. // // scroll one position left:
  48. // lcd.scrollDisplayLeft();
  49. // // wait a bit:
  50. // delay(300);
  51. // }
  52. delay(2000);
  53. }
  54.  
  55. void stringToLCD(String stringIn) {
  56. int lineCount = 0;
  57. int lineNumber = 0;
  58. byte stillProcessing = 1;
  59. byte charCount = 1;
  60. lcd.clear();
  61. lcd.setCursor(0,0);
  62.  
  63. while(stillProcessing) {
  64. if (++lineCount > 16) { // have we printed 20 characters yet (+1 for the logic)
  65. lineNumber += 1;
  66. lcd.setCursor(0,lineNumber); // move cursor down
  67. lineCount = 1;
  68. }
  69.  
  70. lcd.print(stringIn[charCount - 1]);
  71.  
  72. if (!stringIn[charCount]) { // no more chars to process?
  73. stillProcessing = 0;
  74. }
  75. charCount += 1;
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment