Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Keypad.h> //Keypad Bibliothek
- // festlegung der Eingänge
- const int buzzerPin = 13;
- const int ledPin = 12;
- const int motionPin = 11;
- int light = 0;
- // Buzzermodus ist aus
- boolean buzzer_mode = false;
- // LED
- int ledState = LOW;
- long previousMillis = 0;
- long interval = 100; // Interval des Blinkens
- const String code = "123"; // Code zum deaktivieren
- String enteredCode = "";
- const byte rows = 4; // Anzahl an Reihen
- const byte cols = 4; // Anzahl an Spalten
- char keys[rows][cols] = {{'1', '2', '3', 'A'},
- {'4', '5', '6', 'B'},
- {'7', '8', '9', 'C'},
- {'*', '0', '#', 'D'}};
- // Pins für Tastenfeld
- byte rowPins[rows] = {6, 7, 8, 9}; // Pins der Reihen
- byte colPins[cols] = {2, 3, 4, 5}; // Pins der Spalten
- Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
- void setup() {
- Serial.begin(9600);
- // Output für Buzzer und LED
- pinMode(ledPin, OUTPUT);
- pinMode(buzzerPin, OUTPUT);
- // Zeit bis der Alarm startet
- delay(5000);
- }
- void loop() {
- char key = keypad.getKey(); // gedrückte Taste einspeichern
- if (key != NO_KEY) { // überprüfen ob eine Taste gedrückt wurde
- switch (key) {
- case '*':
- enteredCode = ""; // bereits gespeicherte Zeichen löschen
- break;
- case 'A':
- if (enteredCode == code) { // überprüft ob der eingegebene Code dem
- // benötigtem Code entspricht
- buzzer_mode = false;
- enteredCode = "";
- }
- break;
- default:
- if (isDigit(key)) {
- enteredCode += key; // fügt die Taste zum gedrükten Code hinzu
- }
- break;
- }
- }
- light = analogRead(0);
- Serial.print("Sensorwert = ");
- Serial.println(light);
- if (light < 200) // Fototansistor analoger Eingang/WEnn 0V dann Alarm
- {
- buzzer_mode = true;
- }
- // Bewegung wird endeckt= alarm an
- if (digitalRead(motionPin)) {
- buzzer_mode = true;
- }
- // Wenn Alarm an dann LED auch
- if (buzzer_mode) {
- long currentMillis = millis();
- if (currentMillis - previousMillis > interval) {
- previousMillis = currentMillis;
- if (ledState == LOW)
- ledState = HIGH;
- else
- ledState = LOW;
- // Switch the LED
- digitalWrite(ledPin, ledState);
- }
- tone(buzzerPin, 1000);
- } else { // Wenn der Alarm aus ist
- // kein Sound und kein Licht
- noTone(buzzerPin);
- digitalWrite(ledPin, LOW);
- }
- }
Add Comment
Please, Sign In to add comment