awinograd

EE 47 - Lab 4 - Accelerometer -> LCD

Apr 30th, 2012
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.06 KB | None | 0 0
  1. // these constants describe the pins. They won't change:
  2. const int xpin = A2;                  // x-axis of the accelerometer
  3. const int ypin = A3;                  // y-axis
  4. const int zpin = A4;                  // z-axis (only on 3-axis models)
  5.  
  6. // include the library code:
  7. #include <LiquidCrystal.h>
  8.  
  9. // initialize the library with the numbers of the interface pins
  10. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  11.  
  12. void setup()
  13.  
  14. {
  15.   // initialize the serial communications:
  16.   Serial.begin(9600);
  17.   lcd.begin(16, 2);
  18. }
  19.  
  20. void loop()
  21. {
  22.   // print the sensor values:
  23.   String readings = "X"+(String)analogRead(xpin);
  24.   readings += " Y:";
  25.   readings += (String)analogRead(ypin);
  26.   readings += " Z:";
  27.   readings += (String)analogRead(zpin);
  28.   // print a tab between values:
  29.   lcd.clear();
  30.   lcd.print(readings);
  31.   Serial.print(analogRead(xpin));
  32.   Serial.print("\t");
  33.   Serial.print(analogRead(ypin));
  34.   // print a tab between values:
  35.   Serial.print("\t");
  36.   Serial.print(analogRead(zpin));
  37.   Serial.println();
  38.  
  39.   // delay before next reading:
  40.   delay(100);
  41. }
Advertisement
Add Comment
Please, Sign In to add comment