Guest User

Untitled

a guest
May 26th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. #include <Keypad.h> //Keypad Bibliothek
  2.  
  3. // festlegung der Eingänge
  4. const int buzzerPin = 13;
  5. const int ledPin = 12;
  6. const int motionPin = 11;
  7. int light = 0;
  8.  
  9. // Buzzermodus ist aus
  10. boolean buzzer_mode = false;
  11.  
  12. // LED
  13. int ledState = LOW;
  14. long previousMillis = 0;
  15. long interval = 100; // Interval des Blinkens
  16.  
  17. const String code = "123"; // Code zum deaktivieren
  18. String enteredCode = "";
  19.  
  20. const byte rows = 4; // Anzahl an Reihen
  21. const byte cols = 4; // Anzahl an Spalten
  22. char keys[rows][cols] = {{'1', '2', '3', 'A'},
  23. {'4', '5', '6', 'B'},
  24. {'7', '8', '9', 'C'},
  25. {'*', '0', '#', 'D'}};
  26. // Pins für Tastenfeld
  27. byte rowPins[rows] = {6, 7, 8, 9}; // Pins der Reihen
  28. byte colPins[cols] = {2, 3, 4, 5}; // Pins der Spalten
  29. Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, rows, cols);
  30.  
  31. void setup() {
  32. Serial.begin(9600);
  33. // Output für Buzzer und LED
  34. pinMode(ledPin, OUTPUT);
  35. pinMode(buzzerPin, OUTPUT);
  36.  
  37. // Zeit bis der Alarm startet
  38. delay(5000);
  39. }
  40.  
  41. void loop() {
  42.  
  43. char key = keypad.getKey(); // gedrückte Taste einspeichern
  44.  
  45. if (key != NO_KEY) { // überprüfen ob eine Taste gedrückt wurde
  46. switch (key) {
  47. case '*':
  48. enteredCode = ""; // bereits gespeicherte Zeichen löschen
  49. break;
  50. case 'A':
  51. if (enteredCode == code) { // überprüft ob der eingegebene Code dem
  52. // benötigtem Code entspricht
  53. buzzer_mode = false;
  54. enteredCode = "";
  55. }
  56. break;
  57. default:
  58. if (isDigit(key)) {
  59. enteredCode += key; // fügt die Taste zum gedrükten Code hinzu
  60. }
  61. break;
  62. }
  63. }
  64.  
  65. light = analogRead(0);
  66. Serial.print("Sensorwert = ");
  67. Serial.println(light);
  68. if (light < 200) // Fototansistor analoger Eingang/WEnn 0V dann Alarm
  69. {
  70. buzzer_mode = true;
  71. }
  72.  
  73. // Bewegung wird endeckt= alarm an
  74. if (digitalRead(motionPin)) {
  75. buzzer_mode = true;
  76. }
  77. // Wenn Alarm an dann LED auch
  78. if (buzzer_mode) {
  79. long currentMillis = millis();
  80. if (currentMillis - previousMillis > interval) {
  81. previousMillis = currentMillis;
  82. if (ledState == LOW)
  83. ledState = HIGH;
  84. else
  85. ledState = LOW;
  86. // Switch the LED
  87. digitalWrite(ledPin, ledState);
  88. }
  89. tone(buzzerPin, 1000);
  90. } else { // Wenn der Alarm aus ist
  91. // kein Sound und kein Licht
  92. noTone(buzzerPin);
  93. digitalWrite(ledPin, LOW);
  94. }
  95. }
Add Comment
Please, Sign In to add comment