Advertisement
ace_ventura

termo_comm

Sep 28th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.40 KB | None | 0 0
  1. #include <wiringPi.h>
  2. #include <stdio.h>
  3. #include <math.h>
  4.  
  5. //Declara a porta 7 como o PWM
  6. #define PWM    7
  7. #define LAMP   2
  8. #define TE     3
  9. #define CONT   5000000
  10.  
  11. int main (void) {
  12.  
  13.   int high=0, low=0, read=0, i;
  14.   float resistance=0, temperature=0, vref = 0;
  15.   float (dutyCycle);
  16.  
  17.   printf("\n");
  18.   printf("Leitura da temperatura através do RasPi\n\n");
  19.  
  20.   wiringPiSetup ();
  21.   //Configura a porta 7 como entrada
  22.   pinMode(PWM, INPUT);
  23.   pinMode(LAMP, OUTPUT);
  24.   pinMode(TE, OUTPUT);
  25.  
  26.   for(;;) {
  27.     for (i=0; i<CONT; i++) {
  28.  
  29.       read = digitalRead(PWM);
  30.  
  31.       if(read){
  32.         high++;
  33.       }
  34.  
  35.       else {
  36.         low++;
  37.       }
  38.  
  39.     }
  40.  
  41.     dutyCycle = (float)high/(high+low);
  42.     high = 0;
  43.     low = 0;
  44.     vref = 5.0*dutyCycle;
  45.     resistance = (float)(1936*vref)/(5-vref);
  46.     temperature = -log(resistance/6883)/0.03774;
  47.  
  48.     printf("Tensão de Referência: %0.2f V\n", vref);
  49.     printf("Duty Cycle: %0.2f %\n", 100*dutyCycle);
  50.     printf("Temperatura: %0.2f ºC\n", temperature);
  51.     printf("\n");
  52.  
  53.     if (temperature > 43) {
  54.       digitalWrite(LAMP, LOW);
  55.       delay(50);
  56.       digitalWrite(TE, LOW);
  57.       delay(50);
  58.       digitalWrite(TE, HIGH);
  59.     }
  60.  
  61.     else if (temperature < 42) {
  62.       digitalWrite(LAMP, HIGH);
  63.       delay(50);
  64.       digitalWrite(TE, LOW);
  65.       delay(50);
  66.       digitalWrite(TE, HIGH);
  67.     }
  68.  
  69.   }
  70.  
  71.   return 0;
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement