답변 : 터치센서를 이용한 아두이노 선풍기 코딩 도와주십시오
페이지 정보
작성자 master 작성일18-12-11 23:06 조회3,647회 댓글0건본문
//
const int switchPin=7;
const int motorPin=9;
//
int switchState=0;
int motorState=0;
//
void setup(){
pinMode(motorPin,OUTPUT);
pinMode(switchPin,INPUT);
}
//
void loop(){
if(digitalRead(switchPin)){
if(switchState==0){ switchState=1;
if(motorState){ motorState=0; digitalWrite(motorPin,LOW); }
else { motorState=1; digitalWrite(motorPin,HIGH); }
}
}
else switchState=0;
}
//-------------------------------------------------------------------------
터치센서를 누르면 선풍기가 켜지고,다시 한번 더 누르면 선풍기가 꺼지도록하고 싶은데
안됩니다ㅠㅠㅠ내일 시험인데 제발 도와주십시오!
댓글 : 0
조회수 : 3,647
등록된 댓글이 없습니다.