티스토리 뷰
<준비물>
ㅇ Arduino
ㅇ 만능기판
ㅇ 점퍼 케이블
<연결>
- 5V
- GND
- SCL
- SDA
<Source Code>
/*******************************************************
Name: ADXL345_Example
******************************************************/
#include <Wire.h>
#include <ADXL345.h>
ADXL345 adxl; //variable adxl is an instance of the ADXL345 library
void setup(){
Serial.begin(9600);
adxl.powerOn();
//set activity/ inactivity thresholds (0-255)
adxl.setActivityThreshold(75); //62.5mg per increment
adxl.setInactivityThreshold(75); //62.5mg per increment
adxl.setTimeInactivity(10); // how many seconds of no activity is inactive?
//look of activity movement on this axes - 1 == on; 0 == off
adxl.setActivityX(1);
adxl.setActivityY(1);
adxl.setActivityZ(1);
//look of inactivity movement on this axes - 1 == on; 0 == off
adxl.setInactivityX(1);
adxl.setInactivityY(1);
adxl.setInactivityZ(1);
//look of tap movement on this axes - 1 == on; 0 == off
adxl.setTapDetectionOnX(0);
adxl.setTapDetectionOnY(0);
adxl.setTapDetectionOnZ(1);
//set values for what is a tap, and what is a double tap (0-255)
adxl.setTapThreshold(50); //62.5mg per increment
adxl.setTapDuration(15); //625μs per increment
adxl.setDoubleTapLatency(80); //1.25ms per increment
adxl.setDoubleTapWindow(200); //1.25ms per increment
//set values for what is considered freefall (0-255)
adxl.setFreeFallThreshold(7); //(5 - 9) recommended - 62.5mg per increment
adxl.setFreeFallDuration(45); //(20 - 70) recommended - 5ms per increment
//setting all interupts to take place on int pin 1
//I had issues with int pin 2, was unable to reset it
adxl.setInterruptMapping( ADXL345_INT_SINGLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_DOUBLE_TAP_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_FREE_FALL_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_ACTIVITY_BIT, ADXL345_INT1_PIN );
adxl.setInterruptMapping( ADXL345_INT_INACTIVITY_BIT, ADXL345_INT1_PIN );
//register interupt actions - 1 == on; 0 == off
adxl.setInterrupt( ADXL345_INT_SINGLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_DOUBLE_TAP_BIT, 1);
adxl.setInterrupt( ADXL345_INT_FREE_FALL_BIT, 1);
adxl.setInterrupt( ADXL345_INT_ACTIVITY_BIT, 1);
adxl.setInterrupt( ADXL345_INT_INACTIVITY_BIT, 1);
}
void loop(){
//Boring accelerometer stuff
int x,y,z;
adxl.readAccel(&x, &y, &z); //read the accelerometer values and store them in variables x,y,z
// Output x,y,z values - Commented out
Serial.print("X:");
Serial.print(x);
Serial.print(", Y:");
Serial.print(y);
Serial.print(", Z:");<<
Serial.println(z);
delay(1000);
}
<결과>
1. 그림과 동일한 상태
X:0, Y:0, Z:256
2. 오른쪽(짧은 선을 기준으로 ) 회전
X:0, Y;256, Z:0
3. (다시 1의 위치로 정한 다음) 앞쪽(긴 선을 기준으로) 회전
X:-256, Y:0, Z:0
반응형
'HWDesk > HardwareControl' 카테고리의 다른 글
[Arduino활용18] 원격으로 외부 장치 제어하기(적외선 리모컨 등) (0) | 2020.02.09 |
---|---|
[Arduino] MCP3421 ADC 값 읽기 (0) | 2020.02.08 |
Dual Type Common Anode 7-segment 동작 테스트 (0) | 2020.02.03 |
기울어짐 알람(2) (0) | 2020.02.01 |
기울어짐 알람 (0) | 2020.01.31 |
반응형
250x250
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 허들
- 절연형
- 심심풀이치매방지기
- Innovations&Hurdles
- 오블완
- 혁신과허들
- 혁신
- Hurdles
- bilient
- Video
- 배프
- 심심풀이
- 치매
- Innovation&Hurdles
- 전류
- ServantClock
- Innovations
- DYOV
- image
- badp
- 전압전류모니터링
- 티스토리챌린지
- 전압
- 아두이노
- 빌리언트
- arduino
- 둎
- 치매방지
- BSC
- Decorator
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함