Inclinometer Sketch
#include <math.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int xpin = A2; // x-axis of the accelerometer
const int ypin = A1; // y-axis
const int zpin = A3;// z-axis
int x_data;
int y_data;
int z_data;
float x_rad;
float y_rad;
float degree;
unsigned long time;
void setup() {
// initialize the serial communications:
Serial.begin(57600);
lcd.begin(16,2);
lcd.print("Angle:");
}
void loop() {
x_data = analogRead(xpin);
y_data = analogRead(ypin);
z_data = analogRead(zpin);
//
// /*time = millis();
////
//// Serial.print(time); //prints time since program started
////
////Serial.print("\t"); */
//
// // print the sensor values:
//
//
// // print a tab between values:
//
// Serial.print(x_data);
//
// Serial.print("\t");
//
//
//
// // print a tab between values:
//
// Serial.print(y_data);
//
// Serial.print("\t");
// Serial.println(z_data);
x_rad = x_data-329.9997;
y_rad = y_data-329.9997;
degree = ( atan2(y_rad, x_rad)*180/PI);
//
Serial.println(degree);
lcd.setCursor(0,7);
lcd.print(degree);
//
// delay before next reading:
delay(500);
}
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
const int xpin = A2; // x-axis of the accelerometer
const int ypin = A1; // y-axis
const int zpin = A3;// z-axis
int x_data;
int y_data;
int z_data;
float x_rad;
float y_rad;
float degree;
unsigned long time;
void setup() {
// initialize the serial communications:
Serial.begin(57600);
lcd.begin(16,2);
lcd.print("Angle:");
}
void loop() {
x_data = analogRead(xpin);
y_data = analogRead(ypin);
z_data = analogRead(zpin);
//
// /*time = millis();
////
//// Serial.print(time); //prints time since program started
////
////Serial.print("\t"); */
//
// // print the sensor values:
//
//
// // print a tab between values:
//
// Serial.print(x_data);
//
// Serial.print("\t");
//
//
//
// // print a tab between values:
//
// Serial.print(y_data);
//
// Serial.print("\t");
// Serial.println(z_data);
x_rad = x_data-329.9997;
y_rad = y_data-329.9997;
degree = ( atan2(y_rad, x_rad)*180/PI);
//
Serial.println(degree);
lcd.setCursor(0,7);
lcd.print(degree);
//
// delay before next reading:
delay(500);
}
Comments
Post a Comment