Advertisement
RuiViana

Contador_2Dig_7Seg_Botoes

Oct 11th, 2016
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.30 KB | None | 0 0
  1. #include "SevSeg.h"
  2. SevSeg sevseg;                                    //Instanciar a biblioteca sevseg
  3. #define CONTAR1 11     // pino onde será conectado a tecla de contagem
  4. #define APAGA 13      // pino onde será conectado a tecla de modo
  5. #define CONTAR2 12    // pino onde será conectado a tecla de contagem
  6. byte Dig = 0;
  7.  
  8. //---------------------------
  9. void setup()
  10. {
  11.   pinMode(CONTAR1, INPUT_PULLUP);
  12.   pinMode(APAGA,  INPUT_PULLUP);
  13.   pinMode(CONTAR2, INPUT_PULLUP);
  14.  
  15.   byte numDigits = 2;                              //Números de dígitos do display, é válido para qualquer display (1, 2, 3, 4, n dígitos);
  16.   byte digitPins[] = {9, 10};                     //Pino dos ânodos ou cátodos.
  17.   byte segmentPins[] = {2, 3, 4, 5, 6, 7, 8};      //Pinos dos segmentos do A ao G
  18.   sevseg.begin(COMMON_ANODE, numDigits, digitPins, segmentPins); //Aqui se seu display for cátodo é preciso trocar COMMON_ANODE para COMMON_CATHODE
  19.   sevseg.setBrightness(90);                        //Define o brilho do display
  20. }
  21. //-------------------------
  22. void loop()
  23. {
  24.   if (digitalRead(CONTAR1) == LOW)                 // Se o botão de contar1 estiver apertado
  25.   {
  26.     delay(50);
  27.     if (digitalRead(CONTAR1) == LOW)                 // Se o botão de contar1 continua apertado
  28.     {
  29.       delay(20);
  30.       if (digitalRead(CONTAR1) == HIGH)                 // Se o botão de contar1 foi liberado
  31.       {
  32.         Dig++;
  33.       }
  34.     }
  35.   }
  36.  
  37.   if (digitalRead(CONTAR2) == LOW)                 // Se o botão de  estiver apertado
  38.   {
  39.     delay(50);
  40.     if (digitalRead(CONTAR2) == LOW)                 // Se o botão de  continua apertado
  41.     {
  42.       delay(20);
  43.       if (digitalRead(CONTAR2) == HIGH)                 // Se o botão de  foi liberado
  44.       {
  45.         Dig = Dig + 10;
  46.       }
  47.     }
  48.   }
  49.  
  50.   if (digitalRead(APAGA) == LOW)                 // Se o botão de  estiver apertado
  51.   {
  52.     delay(50);
  53.     if (digitalRead(APAGA) == LOW)                 // Se o botão de  continua apertado
  54.     {
  55.       delay(20);
  56.       if (digitalRead(APAGA) == HIGH)                 // Se o botão de  foi liberado
  57.       {
  58.         Dig = 0;
  59.       }
  60.     }
  61.   }
  62.   sevseg.setNumber(Dig, 1);               // Seta o número que será mostrado no display
  63.   sevseg.refreshDisplay();                // Executar repetidamente
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement