I guess this is a bit trivial, but we all have to start somewhere! I how have a strip of 5 leds acting as a cpu usage indicator. I am particularly pleased with myself as I have not dome much in the way of electronics since school many years ago, and this is my first proper go with Python.
My daughter uses GCompris a lot, we cannot see the usage indicator as the game is full screen, hence my need for an indicator to see why it is sluggish.
Alternatively it is a chance to play with hardware and software and quickly get something that does something in the real world as opposed to on screen.
The code, if you are interested is here:
Code: Select all
#!/usr/bin/python
#CPU utilisaton indicator comprising 5 leds indicating cpu usage
#of greater than 20, 40, 60, 80 and 95%.
#Used when the on-screen indicator cannot be seen, such as with
#full screen games.
#each led has a 470 ohm resistor.
#uses 7 GPIO ports, including 3V3(pin 1) and 0V (pin 6).
import time
import RPi.GPIO as GPIO
import psutil
GPIO.setup(11, GPIO.OUT)
GPIO.setup(12, GPIO.OUT)
GPIO.setup(13, GPIO.OUT)
GPIO.setup(15, GPIO.OUT)
GPIO.setup(16, GPIO.OUT)
while True:
mytime = psutil.cpu_percent(interval=1, percpu=False)
if mytime>20:
GPIO.output(11, False)
else:
GPIO.output(11, True)
if mytime>40:
GPIO.output(12, False)
else:
GPIO.output(12, True)
if mytime>60:
GPIO.output(13, False)
else:
GPIO.output(13, True)
if mytime>80:
GPIO.output(15, False)
else:
GPIO.output(15, True)
if mytime>95:
GPIO.output(16, False)
else:
GPIO.output(16, True)