Advertisement
RuiViana

Medidor_Luz_Solar

Oct 7th, 2017
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #define ldr A0                              // Definicao do port analogico
  2. unsigned int lux(0);                        // Variavel obter medida de sol
  3. unsigned long tempo(0);                     // Variavel para medir intervalos de tempo de sol
  4. unsigned long anterior(0);                  // Variavel para salvar tempo de inicio de contagem
  5. unsigned long sol(0);                       // Variavel para acumular tempo de sol
  6. bool contador(0);                           // Variavel para controle de contagem
  7. //--------------------------
  8. void setup()
  9. {
  10.   Serial.begin(9600);                       // Inicialise serial em 9600 bps
  11.   anterior = millis();                      // Atualize tempo atual                    
  12. }
  13. //--------------------------
  14. void loop()
  15. {
  16.   lux = analogRead(ldr);                    // le port analogico
  17.   if ( lux < 800)                           // Se for menor que 800
  18.   {
  19.     sol = sol + tempo;                      // Acumule tempo de sol
  20.     tempo = 0;                              // Zera o tempo medido
  21.     contador = 0;                           // Desabilite contagem
  22.     anterior = millis();                    // Atualize tempo atual
  23.   }
  24.   else                                      // Se for maior que 800
  25.   {
  26.     contador = 1;                           // Habilite contagem
  27.   }
  28.   if (contador == 1)                        // Se contagem habilitada
  29.   {
  30.     tempo =  (millis() - anterior);         // tempo igual tempo de sol
  31.   }
  32.   Serial.println(sol);                      // Imprime acumulado de tempo de sol
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement