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 LAMP 2
- #define TE 3
- #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 ();
- //Configura a porta 7 como entrada
- pinMode(PWM, INPUT);
- pinMode(LAMP, OUTPUT);
- pinMode(TE, OUTPUT);
- for(;;) {
- 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;
- 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) {
- digitalWrite(LAMP, LOW);
- delay(50);
- digitalWrite(TE, LOW);
- delay(50);
- digitalWrite(TE, HIGH);
- }
- else if (temperature < 42) {
- digitalWrite(LAMP, HIGH);
- delay(50);
- digitalWrite(TE, LOW);
- delay(50);
- digitalWrite(TE, HIGH);
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement