Skip to content

Instantly share code, notes, and snippets.

@ktzar
Created September 23, 2012 23:08
Show Gist options
  • Save ktzar/3773385 to your computer and use it in GitHub Desktop.
Save ktzar/3773385 to your computer and use it in GitHub Desktop.
Changing your screen's brightness from the data in a serial port
import serial, time, os
ser = serial.Serial('/dev/ttyACM0', 9600)
while 1:
time.sleep(0.05)
try:
line = ser.readline().strip()
value = int(line) * 10
command = 'echo "{0}" > /sys/class/backlight/intel_backlight/brightness'.format(value)
os.system(command)
print(command)
except serial.serialutil.SerialException:
print "Error reading from serial"
except OSError:
print "Error reading from serial"
except ValueError:
value = 300
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment