SHARE
TWEET

Untitled

a guest Jan 21st, 2020 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int led = 13;
  2.  
  3. int presenza = 8;
  4. int presenzastate = 0;
  5.  
  6. bool fallingEdge = false;
  7. unsigned long signalTime;
  8.  
  9. void setup () {
  10.   pinMode (led, OUTPUT);
  11.   pinMode (presenza, INPUT_PULLUP); // Abilito il pullup per testare con un pulsante
  12.   delay(3000);    // Altrimenti appena acceso l'uscita viene attivata
  13. }
  14.  
  15.  
  16. void loop () {
  17.   presenzastate = digitalRead(presenza);
  18.   if (presenzastate == LOW && !fallingEdge) {
  19.     fallingEdge = true;
  20.     delay(100);   // Giusto un semplice antirimbalzo del contatto
  21.     signalTime = millis();
  22.   }
  23.  
  24.   if ( millis() - signalTime < 3000) {
  25.     digitalWrite (led, HIGH);
  26.   }
  27.   else {
  28.     digitalWrite(led, LOW);
  29.   }
  30.  
  31.   if (presenzastate) {
  32.     delay(100);   // Un po' di antirimbalzo non fa male nemmeno qui
  33.     fallingEdge = false;
  34.   }
  35.  
  36.  
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top