Skip to content

Example: Display CPU usage

towlerj edited this page May 8, 2020 · 4 revisions

This example shows how to display CPU usage with BlinkStick. Green = 0%, Amber = 50%, Red = 100%.

This tutorial requires psutil. Install it via:

pip install psutil
from blinkstick import blinkstick
import psutil

bstick = blinkstick.find_first()

if bstick is None:
    print ("No BlinkSticks found...")
else:
    print ("Displaying CPU usage (Green = 0%, Amber = 50%, Red = 100%)")
    print ("Press Ctrl+C to exit")
    
    #go into a forever loop
    while True:
        cpu = psutil.cpu_percent(interval=1)
        intensity = int(255 * cpu / 100)

        bstick.set_color(red=intensity, green=255 - intensity, blue=0)