Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <wiringPi.h>
- #include <stdio.h>
- #include <math.h>
- //Declara a porta 7 como o PWM
- #define PWM 7
- #define CONT 5000000
- int main (void) {
- int high=0, low=0, read=0, i;
- float resistance=0, temperature=0, vref = 0;
- float dutyCycle;
- printf("\n");
- printf("Leitura da temperatura através do RasPi\n\n");
- wiringPiSetup ();
- pinMode(PWM, INPUT);//Configura a porta 7 como entrada
- pinMode(1, OUTPUT);//Configura a porta 1 do wiringPi (pino 12 no header) como saída
- for(;;) { //cálculo do duty cycle
- for (i=0; i<CONT; i++) {
- read = digitalRead(PWM);
- if(read){
- high++;
- } else {
- low++;
- }
- }
- dutyCycle = (float)high/(high+low);
- high = 0;
- low = 0;
- vref = 5.0*dutyCycle;
- resistance = (float)(1936*vref)/(5-vref);
- temperature = -log(resistance/6883)/0.03774;//conversão de dutycycle para temperatura
- printf("Tensão de Referência: %0.2f V\n", vref);
- printf("Duty Cycle: %0.2f %\n", 100*dutyCycle);
- printf("Temperatura: %0.2f ºC\n", temperature);
- printf("\n");
- if (temperature > 43) { //temperatura de chaveamento do rele
- digitalWrite(1, LOW);
- }else if (temperature < 42) {
- digitalWrite(1, HIGH);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement