Skip to content

Instantly share code, notes, and snippets.

@banditkroot banditkroot/cb_cpu.py
Last active Jan 14, 2017

Embed
What would you like to do?
CPU load with Codebug tether
#!/usr/bin/python3
import codebug_tether
import psutil
import time
cb = codebug_tether.CodeBug('/dev/ttyACM0')
def setcol(x):
if x == 1:
return 0b11000
if x == 2:
return 0b11100
if x == 3:
return 0b11110
if x == 4:
return 0b11111
return 0b10000
l0 = 0
l1 = 0
l2 = 0
l3 = 0
l4 = 0
d = 0.01
while True:
cpuload = (psutil.cpu_percent(interval = 1) // 20) - 1
l0 = l1
l1 = l2
l2 = l3
l3 = l4
l4 = setcol(cpuload)
cb.set_col(0, l0)
cb.set_col(1, l1)
cb.set_col(2, l2)
cb.set_col(3, l3)
cb.set_col(4, l4)
time.sleep(d)
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.