-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathADSLLCD.ino
More file actions
43 lines (36 loc) · 1.09 KB
/
ADSLLCD.ino
File metadata and controls
43 lines (36 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const int xPin = 3; // X output of the accelerometer
const int yPin = 2; // Y output of the accelerometer
void setup() {
// initialize serial communications:
Serial.begin(9600);
// initialize the pins connected to the accelerometer
// as inputs:
pinMode(xPin, INPUT);
pinMode(yPin, INPUT);
lcd.begin(16,2);
}
void loop() {
// variables to read the pulse widths:
int pulseX, pulseY;
// variables to contain the resulting accelerations
int accelerationX, accelerationY;
// read pulse from x- and y-axes:
pulseX = pulseIn(xPin,HIGH);
pulseY = pulseIn(yPin,HIGH);
// convert the pulse width into acceleration
// accelerationX and accelerationY are in milli-g's:
// earth's gravity is 1000 milli-g's, or 1g.
accelerationX = ((pulseX / 10) - 500) * 8;
accelerationY = ((pulseY / 10) - 500) * 8;
// print the acceleration
lcd.setCursor(0,1);
lcd.print(accelerationX);
// print a tab character:
lcd.print("\t");
lcd.setCursor(1,0);
lcd.print(accelerationY);
lcd.println();
delay(100);
}