Created
April 4, 2014 19:12
-
-
Save azertyfun/9981262 to your computer and use it in GitHub Desktop.
Script that can power a led with the raspberry pi, using GPIO_11 (physical 23) and GRND (physical 14) when CPU usage > 50%
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import psutil | |
import sys | |
import os | |
try: | |
import RPi.GPIO as GPIO | |
except RuntimeError: | |
print("ERROR : This program needs to be executed as root") | |
sys.exit() | |
if os.geteuid() != 0: | |
print("ERROR : This program needs to be executed as root") | |
sys.exit() | |
GPIO.setmode(GPIO.BOARD) | |
cpu_usage = 0 | |
print "Will now turn on GPIO_11 (23) when CPU usage > 50%" | |
while 1: | |
cpu_usage = psutil.cpu_percent(1) | |
if cpu_usage > 50: | |
GPIO.setup(23, GPIO.OUT) | |
GPIO.output(23, GPIO.HIGH) | |
else: | |
GPIO.setup(23, GPIO.OUT) | |
GPIO.output(23, GPIO.LOW) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment