bal_gennady

OrangePi fan control via terminals GPIO

Nov 3rd, 2019
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <wiringPi.h>
  2. #include <stdio.h>
  3. #include <unistd.h>
  4. #define N 2
  5. int main (void) {
  6.     wiringPiSetup();
  7.     pinMode(1,OUTPUT);
  8.     int temp;
  9.     char arr[N];
  10.     FILE *file;
  11.     while(1) {
  12.         file = fopen("/sys/class/thermal/thermal_zone0/temp" , "r");
  13.         fgets(arr,4,file);
  14.         fclose(file);
  15.         temp=(arr[0]-'0')*10+arr[1]-'0';
  16.         printf("%i\n", temp);
  17.         if(temp>55)
  18.             digitalWrite(1,HIGH);
  19.         else
  20.             digitalWrite(1,LOW);
  21.         delay(10000);
  22.     }
  23.     return 0;
  24. }
Add Comment
Please, Sign In to add comment