forked from geekworm-com/x-c1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfan.py
35 lines (27 loc) · 760 Bytes
/
fan.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
import pigpio
import time
servo = 18
pwm = pigpio.pi()
pwm.set_mode(servo, pigpio.OUTPUT)
pwm.set_PWM_frequency( servo, 25000 )
pwm.set_PWM_range(servo, 100)
while(1):
#get CPU temp
file = open("/sys/class/thermal/thermal_zone0/temp")
temp = float(file.read()) / 1000.00
temp = float('%.2f' % temp)
file.close()
if(temp > 30):
pwm.set_PWM_dutycycle(servo, 40)
if(temp > 50):
pwm.set_PWM_dutycycle(servo, 50)
if(temp > 60):
pwm.set_PWM_dutycycle(servo, 70)
if(temp > 70):
pwm.set_PWM_dutycycle(servo, 80)
if(temp > 75):
pwm.set_PWM_dutycycle(servo, 100)
if(temp < 30):
pwm.set_PWM_dutycycle(servo, 0)
time.sleep(1)