Skip to content

Instantly share code, notes, and snippets.

@dlech
Last active November 13, 2016 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dlech/f7c8313606c75968e259 to your computer and use it in GitHub Desktop.
Save dlech/f7c8313606c75968e259 to your computer and use it in GitHub Desktop.
ev3dev LED color demo
#!/usr/bin/env python
import time
LED_PATH = "/sys/class/leds/ev3:%(color)s:%(direction)s/brightness"
def do_up_down(f1, f2, f3, f4):
for i in range(0, 256):
val1 = str(i)
val2 = str(255-i)
if f1:
f1.write(val1)
if f2:
f2.write(val2)
if f3:
f3.write(val2)
if f4:
f4.write(val1)
time.sleep(0.03)
def main():
f1 = open(LED_PATH % { "color": "green", "direction": "left" }, "w", 0)
f2 = open(LED_PATH % { "color": "red", "direction": "left" }, "w", 0)
f3 = open(LED_PATH % { "color": "green", "direction": "right" }, "w", 0)
f4 = open(LED_PATH % { "color": "red", "direction": "right" }, "w", 0)
# assumes starting with green LEDs illuminated
# dims green LEDs only to off
do_up_down(None, f1, f3, None)
time.sleep(0.5)
# brings red LEDs only to full
do_up_down(f2, None, None, f4)
time.sleep(0.1)
# fades left LED from red to green and right LED from green to red
do_up_down(f1, f2, f3, f4)
# fades left LED from green to red and right LED from red to green
do_up_down(f2, f1, f4, f3)
# return to full green only state
f1.write("255")
f2.write("0")
f3.write("255")
f4.write("0")
if __name__ == "__main__":
main()
@romainschmid
Copy link

I copied and pasted this in a file, ran it but... didn't work.
robot@ev3dev:~/tests$ python essaiLeds.py Traceback (most recent call last): File "essaiLeds.py", line 44, in <module> main() File "essaiLeds.py", line 22, in main f1 = open(LED_PATH % { "color": "green", "direction": "left" }, "w", 0) IOError: [Errno 2] No such file or directory: '/sys/class/leds/ev3:green:left/brightness' robot@ev3dev:~/tests$

I have Brickman 0.8.0
kernel 4.4.24-16-ev3dev-ev3

Is it me, my config or... your script ?
Thanks for any clue.

@webmanoffesto
Copy link

webmanoffesto commented Nov 13, 2016

I also got an error message
Traceback (most recent call last): File "led-color-demo.py", line 44, in <module> main() File "led-color-demo.py", line 22, in main f1 = open(LED_PATH % { "color": "green", "direction": "left" }, "w", 0) IOError: [Errno 2] No such file or directory: '/sys/class/leds/ev3:green:left/brightness'
I'm running the latest ev3dev 3.16.7
on a Lego Mindstorms EV3 brick

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment