반응형

부저 알람용 코드.

삐삐삐삐~ 삐삐삐삐~

OnTime = 50;
OffTime = 50;
unsigned long curr_ms = millis();

if ((buzzerState == HIGH) && (curr_ms - prev_ms >= OnTime)) {
    buzzerState = LOW;
    prev_ms = curr_ms;
    digitalWrite(buzzerPin, buzzerState);
    buzzerCnt++;

} else if ((buzzerState == LOW) && (curr_ms - prev_ms >= OffTime)) {
    if (buzzerCnt < buzzerOnCnt) {
        buzzerState = HIGH;
    } else buzzerCnt++;
    prev_ms = curr_ms;
    if (buzzerCnt < buzzerOnCnt)
    digitalWrite(buzzerPin, buzzerState);
}

if (buzzerCnt >= buzzerOnCnt + buzzerOffCnt) buzzerCnt = 0;

첫번째 테스트 코드... 결과는 다른 알람과 비슷했다.

반응형

관련글