Skip to content

Instantly share code, notes, and snippets.

@miawgogo
Created October 20, 2016 11:48
Show Gist options
  • Select an option

  • Save miawgogo/bf8937e0d86cf20723ca30c9cbe2cac9 to your computer and use it in GitHub Desktop.

Select an option

Save miawgogo/bf8937e0d86cf20723ca30c9cbe2cac9 to your computer and use it in GitHub Desktop.
int meter = 11; // blue LED in Digital Pin 9 (PWM)
int old = 0;
void setup(){
Serial.begin(9600);
pinMode(meter,OUTPUT); // tell arduino it's an output
// test and set all the outputs to low
digitalWrite(meter,LOW);
}
void loop(){
int msg;
msg = int(Serial.read());
int x = msg;
if (x == -1){return;}
analogWrite(meter,x);old=x;Serial.println(x,HEX);
}
#!/usr/bin/env python
from linux_metrics import cpu_stat
import serial
import time
port = serial.Serial('/dev/ttyACM0', 9600)
while True:
idle = cpu_stat.cpu_percents()
idle = idle['idle']/100
val = 255 * (1-idle)
val = int(str(val).split('.')[0])
print(val)
port.write(bytes(val))
time.sleep(0.25)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment