Advertisement
RuiViana

Liga_Desliga_Rele

Oct 14th, 2016
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #define Botao 5
  2. #define Rele 6
  3. //------------------------------
  4. void setup()
  5. {
  6.   pinMode(Botao, INPUT_PULLUP);
  7.   pinMode(Rele, OUTPUT);
  8. }
  9. //------------------------------
  10. void loop()
  11. {
  12.   while (digitalRead(Botao) == LOW)                   // Se o botao estiver apertado
  13.   {
  14.     delay(2);
  15.     while (digitalRead(Botao) == LOW)                 // Se o botao continua apertado
  16.     {
  17.       delay(2);
  18.       if (digitalRead(Botao) == HIGH)                 // Se o botao foi liberado
  19.       {
  20.         digitalWrite(Rele, LOW);                      // Liga rele
  21.         delay(1000);
  22.         digitalWrite(Rele, HIGH);                     // Desliga rele
  23.       }
  24.     }
  25.   }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement