Advertisement
uaa

_eman_8.cpp output from p11_CrystalBall.ino

uaa
Mar 16th, 2014
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. #line 1 "p11_CrystalBall.ino"
  2. /*
  3. Arduino Starter Kit example
  4. Project 11 - Crystal Ball
  5.  
  6. This sketch is written to accompany Project 11 in the
  7. Arduino Starter Kit
  8.  
  9. Parts required:
  10. 220 ohm resistor
  11. 10 kilohm resistor
  12. 10 kilohm potentiometer
  13. 16x2 LCD screen
  14. tilt switch
  15.  
  16.  
  17. Created 13 September 2012
  18. by Scott Fitzgerald
  19.  
  20. http://arduino.cc/starterKit
  21.  
  22. This example code is part of the public domain
  23. */
  24.  
  25. // include the library code:
  26. #include <Liquid.h>
  27.  
  28.  
  29. // initialize the library with the numbers of the interface pins
  30. #include "Arduino.h"
  31. void setup();
  32. void loop();
  33. #line 29
  34. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  35.  
  36. // set up a constant for the tilt switchPin
  37. const int switchPin = 6;
  38.  
  39. // variable to hold the value of the switchPin
  40. int switchState = 0;
  41.  
  42. // variable to hold previous value of the switchpin
  43. int prevSwitchState = 0;
  44.  
  45. // a variable to choose which reply from the crystal ball
  46. int reply;
  47.  
  48. void setup() {
  49. // set up the number of columns and rows on the LCD
  50. lcd.begin(16, 2);
  51.  
  52. // set up the switch pin as an input
  53. pinMode(switchPin,INPUT);
  54.  
  55. // Print a message to the LCD.
  56. lcd.print("Ask the");
  57. // set the cursor to column 0, line 1
  58. // line 1 is the second row, since counting begins with 0
  59. lcd.setCursor(0, 1);
  60. // print to the second line
  61. lcd.print("Crystal Ball!");
  62. }
  63.  
  64. void loop() {
  65. // check the status of the switch
  66. switchState = digitalRead(switchPin);
  67.  
  68. // compare the switchState to its previous state
  69. if (switchState != prevSwitchState) {
  70. // if the state has changed from HIGH to LOW
  71. // you know that the ball has been tilted from
  72. // one direction to the other
  73. if (switchState == LOW) {
  74. // randomly chose a reply
  75. reply = random(8);
  76. // clean up the screen before printing a new reply
  77. lcd.clear();
  78. // set the cursor to column 0, line 0
  79. lcd.setCursor(0, 0);
  80. // print some text
  81. lcd.print("the ball says:");
  82. // move the cursor to the second line
  83. lcd.setCursor(0, 1);
  84.  
  85. // choose a saying to print baed on the value in reply
  86. switch(reply){
  87. case 0:
  88. lcd.print("Yes");
  89. break;
  90.  
  91. case 1:
  92. lcd.print("Most likely");
  93. break;
  94.  
  95. case 2:
  96. lcd.print("Certainly");
  97. break;
  98.  
  99. case 3:
  100. lcd.print("Outlook good");
  101. break;
  102.  
  103. case 4:
  104. lcd.print("Unsure");
  105. break;
  106.  
  107. case 5:
  108. lcd.print("Ask again");
  109. break;
  110.  
  111. case 6:
  112. lcd.print("Doubtful");
  113. break;
  114.  
  115. case 7:
  116. lcd.print("No");
  117. break;
  118. }
  119. }
  120. }
  121. // save the current switch state as the last state
  122. prevSwitchState = switchState;
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement