일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- FujiFilm GFX50s
- Kentmere 400
- 2019 유럽여행
- Kodak 5222
- Germany
- 2018 미국출장
- ZeissIkon ZI
- Minolta CLE
- 4870
- FujiFilm C200
- fujifilm velvia 50
- GRD2
- cs50/2.5
- Minolta TC-1
- Hasselblad 500cm
- SONY A7
- N80/4
- Leica M7
- Kodak T-Max 100
- Rollei35s
- cf80/2.8
- G28/2.8
- M-Rokkor 40/2
- cf50/4 fle
- kodak t-max 400
- Contax G2
- Kodak 400TX
- Mamiya 7
- Nikon 28Ti
- Kodak Ektar 100
- Today
- Total
J 창고
[Arduino] GY-61 ADXL335 Accelerometer 본문
x, y, z 3축 아날로그 출력 센서
//////////////////////////////////////////////////////////////////
//©2011 bildr
//Released under the MIT License - Please reuse change and share
//Simple code for the ADXL335, prints calculated orientation via serial
//////////////////////////////////////////////////////////////////
//Analog read pins
const int xPin = A3;
const int yPin = A2;
const int zPin = A1;
//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 265;
int maxVal = 402;
//to hold the caculated values
double x;
double y;
double z;
void setup(){
Serial.begin(9600);
}
void loop(){
//read the analog values from the accelerometer
int xRead = analogRead(xPin);
int yRead = analogRead(yPin);
int zRead = analogRead(zPin);
//convert read values to degrees -90 to 90 - Needed for atan2
int xAng = map(xRead, minVal, maxVal, -90, 90);
int yAng = map(yRead, minVal, maxVal, -90, 90);
int zAng = map(zRead, minVal, maxVal, -90, 90);
//Caculate 360deg values like so: atan2(-yAng, -zAng)
//atan2 outputs the value of -π to π (radians)
//We are then converting the radians to degrees
x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);
//Output the caculations
Serial.print("x: ");
Serial.print(x);
Serial.print(" | y: ");
Serial.print(y);
Serial.print(" | z: ");
Serial.println(z);
delay(1);//just here to slow down the serial output - Easier to read
}