Advertisement
RuiViana

Pisca_LED_3Minutos

Jul 8th, 2016
3,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define led 13                                    // Define port 13 como led
  2. #define botton 7                                  // Define port 7 como botton
  3. byte FlagLed = 0;                                 // Variavel para controle
  4. byte LedSt = 0;                                   // Status do led
  5. unsigned long Tempo = 0;                          // Variavel para tempo
  6. //----------------------------------
  7. void setup()
  8. {
  9.   pinMode(led, OUTPUT);                           // Define port led como saída
  10.   pinMode(botton, INPUT_PULLUP);                  // Define port botton com entrada com pullup
  11.   digitalWrite(led, LOW);                         // inicia com Led apagado
  12.   Tempo = millis();                               // Estabelece tempo inicial
  13. }
  14. //----------------------------------
  15. void loop()
  16. {
  17.   Tempo = millis();                               // Restaura valor de tempo
  18.   if (digitalRead(botton) == LOW)                 // Se botton foi apertado
  19.   {
  20.     delay(10);                                    // delay para evitar bouncing
  21.     if (digitalRead(botton) == LOW)               // Se botton continua apertado
  22.     {
  23.       FlagLed = 1;                                // Indica botton apertado
  24.     }
  25.   }
  26.   if (digitalRead(botton) == HIGH)                // Se botão esta solto
  27.   {
  28.     while (FlagLed == 1)                             // Se botton foi apertados
  29.     {
  30.       if (millis() - Tempo > 3000)                // Se passaram 3 minutos 180.000ms
  31.       //if (millis() - Tempo > 2000)                // Se passaram 2 segundos (teste)
  32.       {
  33.         LedSt = !digitalRead(led);                // le status do led invertido em Ledst
  34.         digitalWrite(led, LedSt);                 // Acende ou apaga Led
  35.         Tempo = millis();                         // Restaura valor de tempo
  36.         FlagLed = 0;                              // Desliga indicador de botton apertado
  37.       }
  38.     }
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement