Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // these constants describe the pins. They won't change:
- const int xpin = A2; // x-axis of the accelerometer
- const int ypin = A3; // y-axis
- const int zpin = A4; // z-axis (only on 3-axis models)
- // include the library code:
- #include <LiquidCrystal.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- void setup()
- {
- // initialize the serial communications:
- Serial.begin(9600);
- lcd.begin(16, 2);
- }
- void loop()
- {
- // print the sensor values:
- String readings = "X"+(String)analogRead(xpin);
- readings += " Y:";
- readings += (String)analogRead(ypin);
- readings += " Z:";
- readings += (String)analogRead(zpin);
- // print a tab between values:
- lcd.clear();
- lcd.print(readings);
- Serial.print(analogRead(xpin));
- Serial.print("\t");
- Serial.print(analogRead(ypin));
- // print a tab between values:
- Serial.print("\t");
- Serial.print(analogRead(zpin));
- Serial.println();
- // delay before next reading:
- delay(100);
- }
Advertisement
Add Comment
Please, Sign In to add comment