신호의 개수를 설정하고 그 시간대를 알고싶어요!
페이지 정보
작성자 권석호 메일보내기 이름으로 검색 작성일15-05-10 16:44 조회1,339회 댓글2건본문
const int switchPin = 2;
float POT_VC = 1;
float POT_VP = 0;
int count = 0;
long previousMillis = 0;
float a;
float b;
float Voltage ;
float Voltage1 ;
void setup()
{
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH);
Serial.begin(9600);
}
void loop() {
a = digitalRead(switchPin);
if(POT_VP<1 && a>=1)
{
count++;
}
POT_VP = a;
unsigned long currentMillis = millis();
if(currentMillis - previousMillis > 5000)
{
int B = count*12;
Serial.println(B);
previousMillis = currentMillis;
count =0;
}
}
이 코딩은 리드스위치에서 자석을 감지하면 5초마다 신호가 몇번 감지됬나 나타내주는 겁니다.
근데 제가 이 신호가 5번 감지될때의 시간(초)를 알고자 하려고 합니다 어떻게 바꾸면 되는지 알려주실 수 있나요??ㅠㅠ
댓글목록
하드카피님의 댓글

5번 감지될 때의 시간은 count == 5 일 때의 시간을 구하면 될 것 같네요
if(count == 5) {
unsigned long countTime = millis();
}
권석호님의 댓글
권석호 이름으로 검색
넵!! 정말 감사합니다^^