BASIC4MCU | 질문게시판 | 답변 : 알코올 측정기(MQ-3) 관련 질문
페이지 정보
작성자 master 작성일2023-09-19 15:20 조회1,122회 댓글0건본문
int mode=0;
//
void stop(){ digitalWrite(motor1Pin1,0); digitalWrite(motor1Pin2,0); }
void on() { digitalWrite(motor1Pin1,1); digitalWrite(motor1Pin2,0); }
//
void loop(){
int i=analogRead(A5);
if(alcoholValue!=i){ alcoholValue=i; // 알콜 입력값이 변했을 때만 출력
bluetooth.println(alcoholValue); Serial.println(alcoholValue); // 알코올 값 전송
}
//-------------------------------
if(bluetooth.available()>0){
receivedChar = bluetooth.read();
if(receivedChar=='A'){ mode='A'; Serial.println('A'); }
if(receivedChar=='B'){ mode='B'; Serial.println('B'); stop(); bluetooth.println("사용이 종료되었습니다"); }
}
//-------------------------------
if(alcoholValue>alcoholThreshold){ stop(); } // 음주 상태면 무조건 정지
else{
if(digitalRead(buttonPin) && mode=='A'){ mode=0; on(); bluetooth.println("사용이 시작되었습니다"); }
}
//-------------------------------
delay(200);
}
댓글 0
조회수 1,122등록된 댓글이 없습니다.