Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Raspberry Pi Filesystem Activity Fading LED indicator
- # by pyroxide (pyroxi.de)
- #
- # RPi.GPIO as well as psutil is required
- #
- # Both may be installed using pip:
- # $ sudo pip install RPi.GPIO
- # $ sudo pip install psutil
- #
- # or manually:
- # RPi.GPIO: https://aur.archlinux.org/packages/python-raspberry-gpio/
- # psutil: https://pypi.python.org/pypi/psutil/#downloads
- import RPi.GPIO as GPIO
- import time, psutil
- GPIO.setmode(GPIO.BCM)
- GPIO.setwarnings(False)
- sleepTime = 0.01 #length of time between activity checks
- hddled = 3 # hdd activity led GPIO pin number
- dbg = True # debug messages
- increment = 2
- rampingIncrement = 4
- GPIO.setup(hddled, GPIO.OUT)
- led = GPIO.PWM(hddled,100)
- value = 0
- lastValue = 0
- led.start(value)
- oldact = psutil.disk_io_counters()
- ramping = False
- try:
- while (True):
- newact = psutil.disk_io_counters()
- if (ramping):
- value += rampingIncrement
- ramping = (value < 100)
- if ((dbg) and (not ramping)):
- print("ramping=",ramping)
- elif ((newact.read_count > oldact.read_count) or (newact.write_count > oldact.write_count)):
- value = 24
- ramping = True
- if (dbg):
- print("ramping=",ramping)
- else:
- value = max(0,value-increment)
- led.ChangeDutyCycle(max(min(value,100),0))
- if ((dbg) and (value != lastValue)):
- print("value=",value)
- oldact = newact
- time.sleep(sleepTime)
- except KeyboardInterrupt:
- led.stop()
- GPIO.cleanup()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement