Page 217 - 완) I MDP 프로젝트 작품 보고서(전체과 1학년)1.6
P. 217
2) Source Program
#include <Wire.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(12,11); //12번 핀 = BT rx, 11번 핀 = BT tx
int MPU_Address = 0x68; //MPU6050의 고유 주소값 -> 이 주소로 기울기센서의 데이터를 받아
옴
int check; //장비가 어떤 방향으로 가방에 들어있는지 확인하여 감시모드의 축을
정하는 변수
int AcX, AcY, AcZ; //X, Y, Z방향의 기울기 저장 변수
int recive = 0; //BlueTooth로 수신되는 값 저장 변수
int buzzerPin = 10; //buzzer 연결핀 = 10
boolean state = false; //감시모드 ON/OFF 설정 변수
void setup() {
// put your setup code here, to run once:
Wire.begin(); //I2C통신 시작
Wire.beginTransmission(MPU_Address); //MPU-6050의주소값으로 MPU-6050에 접근
Wire.write(0x6B); //MPU-6050초기화
Wire.write(0);
Wire.endTransmission(); //I2C통신 종료(MPU-6050와의 통신 종료)
Serial.begin(115200); //시리얼 포트 초기화(9600)
mySerial.begin(9600); //BlueTooth 통신 포트 초기화(9600)
pinMode(buzzerPin, OUTPUT); //buzzerPin(10) = 출력
}
void loop() {
// put your main code here, to run repeatedly:
BTcom();
MPU6050_action();
}
void BTcom(){ //BlueTooth 통신 함수
if(mySerial.available() > 0){
recive = mySerial.read();
if(recive == 0){
state = false;
- 210 -