Advertisement
Push28

Fan npn control with led temp meter

Apr 7th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import os
  4. import commands
  5. import RPi.GPIO as GPIO
  6. import time
  7. GPIO.setwarnings(False)
  8. GPIO.cleanup()
  9. GPIO.setmode (GPIO.BOARD)
  10. GPIO.setup(33,GPIO.OUT)
  11. GPIO.setup(35,GPIO.OUT)
  12. GPIO.setup(36,GPIO.OUT)
  13. GPIO.setup(37,GPIO.OUT)
  14. GPIO.setup(38,GPIO.OUT)
  15. GPIO.setup(40,GPIO.OUT)
  16. p = GPIO.PWM(33,150)
  17. p.start(0)
  18. n = []
  19. x = 1
  20. while True:
  21.     tempFile = open( "/sys/class/thermal/thermal_zone0/temp" )
  22.     cpu_temp = tempFile.read()
  23.     tempFile.close()
  24.     n = int(cpu_temp)/1000
  25. #   print(n)
  26.     if n < 40:
  27.         p.ChangeDutyCycle(10.0)
  28.         GPIO.output(35,GPIO.HIGH)
  29.         GPIO.output(36,GPIO.LOW)
  30.         GPIO.output(37,GPIO.LOW)
  31.         GPIO.output(38,GPIO.LOW)
  32.         GPIO.output(40,GPIO.LOW)
  33.         time.sleep(3)
  34.     elif n > 40 and n < 45:
  35.         p.ChangeDutyCycle(25.0)
  36.         GPIO.output(35,GPIO.HIGH)
  37.         GPIO.output(36,GPIO.HIGH)
  38.         GPIO.output(37,GPIO.LOW)
  39.         GPIO.output(38,GPIO.LOW)
  40.         GPIO.output(40,GPIO.LOW)
  41.         time.sleep(3)
  42.     elif n > 45 and n < 50:
  43.         p.ChangeDutyCycle(50.0)
  44.         GPIO.output(35,GPIO.HIGH)
  45.         GPIO.output(36,GPIO.HIGH)
  46.         GPIO.output(37,GPIO.HIGH)
  47.         GPIO.output(38,GPIO.LOW)
  48.         GPIO.output(40,GPIO.LOW)
  49.         time.sleep(3)
  50.     elif n > 50 and n < 55:
  51.         p.ChangeDutyCycle(75.0)
  52.         GPIO.output(35,GPIO.HIGH)
  53.         GPIO.output(36,GPIO.HIGH)
  54.         GPIO.output(37,GPIO.HIGH)
  55.         GPIO.output(38,GPIO.HIGH)
  56.         GPIO.output(40,GPIO.LOW)
  57.         time.sleep(3)
  58.     elif n > 55:
  59.         p.ChangeDutyCycle(100.0)
  60.         GPIO.output(35,GPIO.HIGH)
  61.         GPIO.output(36,GPIO.HIGH)
  62.         GPIO.output(37,GPIO.HIGH)
  63.         GPIO.output(38,GPIO.HIGH)
  64.         GPIO.output(40,GPIO.HIGH)
  65.         time.sleep(3)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement