BASIC4MCU | 질문게시판 | 답변 : 아두이노 스위치 질문입니다.
페이지 정보
작성자 master 작성일2022-12-10 19:03 조회1,028회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=22148
본문
#include<Servo.h>
Servo myservo;
//
int cds=A2,seonsor=13,sw=7;
//
void setup(){
pinMode(A1,OUTPUT);
myservo.attach(9); myservo.write(0);
Serial.begin(9600);
}
//
void loop(){
int degree=analogRead(cds); Serial.println(cdsval);
degree=map(degree,0,1023,0,179); Serial.println(degree);
//
if(digitalRead(7)==HIGH){
if(digitalRead(7)==HIGH){ myservo.write(degree); delay(200); }
}
delay(1000);
}
if(digitalRead(7)==HIGH){
if(digitalRead(7)==HIGH){ myservo.write(degree); delay(200); }
}
첫번째 스위치 검출하고나서안에 있는 두번째 if문 실행까지 걸리는 시간은 수us 밖에 안걸립니다.슈퍼맨이라도 이렇게 빠르게 클릭하지 못 할겁니다.
이 예제에서는 moderk 1~3까지 증가하는데
mode==2 일 때 원하는 두 번 클릭이 되겠습니다.
댓글 0
조회수 1,028등록된 댓글이 없습니다.