Skip to content

Instantly share code, notes, and snippets.

@raspberrycoulis raspberrycoulis/cpu.py
Last active Jul 7, 2017

Embed
What would you like to do?
Display CPU usage on Pimoroni's Scroll pHAT HD
#!/usr/bin/env python
import sys
import time
try:
import psutil
except ImportError:
sys.exit("This script requires the psutil module\nInstall with: sudo pip install psutil")
import scrollphathd as sphd
print("""
Scroll pHAT HD: CPU
Displays a graph with CPU values.
Press Ctrl+C to exit!
""")
i = 0
cpu_values = [0] * sphd.DISPLAY_WIDTH
sphd.rotate(180)
while True:
try:
cpu_values.pop(0)
cpu_values.append(psutil.cpu_percent())
sphd.set_graph(cpu_values, low=0, high=25, brightness=0.25)
sphd.show()
time.sleep(0.2)
except KeyboardInterrupt:
sphd.clear()
sys.exit(-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.