Facebook
From Chartreuse Water Vole, 6 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 350
  1. #include <Bounce2.h>
  2. #define button 6
  3.  
  4. int offLedPin = 7; //dioda wylaczania alarmu
  5. int buzzerPin = 8; //buzzer alarmowy
  6. int sensorPin = 9; //sensor wody
  7. int stanBuzzer = LOW; //inicjalizacja stanu buzzera
  8. int stanLed = LOW; //inicjalizacja stanu diody
  9. int licznik = 0;
  10.  
  11. Bounce debouncer = Bounce();
  12.  
  13. void setup() {
  14.   // put your setup code here, to run once:
  15.   Serial.begin(9600);
  16.   pinMode(buzzerPin, OUTPUT);
  17.   pinMode(offLedPin, OUTPUT);
  18.   pinMode(sensorPin, INPUT);
  19.   pinMode(button, INPUT_PULLUP);
  20.  
  21.   debouncer.attach(button);
  22.   debouncer.interval(5);
  23.  
  24.  
  25. }
  26.  
  27. void loop() {
  28.  //<---obsluga przycisku
  29.   debouncer.update();
  30.   int value = debouncer.read();
  31.   if(value == LOW){
  32.     licznik++;
  33.     Serial.println(value);
  34.   }
  35.   //----> END
  36.  
  37.  
  38.   if(licznik == 0){
  39.      if(digitalRead(sensorPin) == LOW){
  40.      digitalWrite(offLedPin, LOW);
  41.      digitalWrite(buzzerPin, HIGH);
  42.      }    
  43.   }
  44.  
  45.   if(licznik == 1){
  46.     digitalWrite(buzzerPin, LOW);
  47.     digitalWrite(offLedPin, HIGH);
  48.   }
  49.  
  50.   if(licznik == 2){
  51.     licznik = 0;
  52.   }
  53.  
  54. }