0
我有一個程序在Arduino中檢查LDR傳感器。如果超過設定值,將觸發報警。我如何設置它,使其一直處於觸發狀態,直到檢測到按鈕按鈕被撤防爲止?如何讓蜂鳴器保持開啓(LDR報警)?
代碼:
const int ledPin = 8;
const int buzzerPin = 4;
const int ldrPin = A0;
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(buzzerPin, OUTPUT);
pinMode(ldrPin, INPUT);
}
void loop() {
int ldrStatus = analogRead(ldrPin);
if (ldrStatus >= 30) {
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
} else {
tone(buzzerPin, 100);
digitalWrite(ledPin, HIGH);
delay(100);
noTone(buzzerPin);
digitalWrite(ledPin, LOW);
delay(100);
Serial.println("----------- ALARM ACTIVATED -----------");
}
}