Switch LED off in Python
Forums:
The helpful examples in Python show loops that run forever.
I want to make a sequence that sets the LED to a random colour 10 times, waits 2 seconds and then turns off the LED.
The loop and the change of colours are no problem.
When the code has exited the loop, the LED stays on at the last random colour selected.
I have tried LedBorg.write('000') to no avail, also creating a colour called off with value "ooo" and using LEDBorg.write(off) but the LED stays on at the last random colour in the loop, The code exits the loop correctly. What am I doing wrong pls?
piborg
Sun, 02/17/2013 - 22:05
Permalink
Hmm
The sequence you describe sounds like it should work fine, would you mind posting the code you have written so we can see it?
Kyle
Mon, 02/18/2013 - 12:02
Permalink
Switch LED off in Python
Hi,
Try making sure you import os at the start and adding this code after your loop.
# Import random, time and os
import random, time, os
# After loop has exited wait 2 seconds and switch LED to black
time.sleep(2)
os.system('echo "000" > /dev/ledborg')
Hope this helps.
cfrench
Mon, 02/18/2013 - 18:14
Permalink
Switch off LED
Very helpful, thanks.
Here is my code listing - not elegant, just playing around. I have shown what works and what does not.
piborg
Mon, 02/18/2013 - 18:27
Permalink
I think I see the problem
Glad to hear you have a solution that works, I think the original Python should be
Without the close Python is holding on to the data and not actually writing it to the file (it normally buffers until it sees a newline character, '\n')
Kyle
Wed, 02/20/2013 - 00:40
Permalink
Random LED
I am also very new to python but here is my adaptation of the random script (any pointers welcomed)