Hardware Reference
In-Depth Information
GPIO.output(CH3, ((sequence[index] & 4) == 4))
GPIO.output(CH4, ((sequence[index] & 8) == 8))
#
# Delay... make this as long a you want, or make it variable
#
time.sleep(DELAY)
#
# Advance to the next pattern in the sequence
#
index = index + 1
if (index >= len(sequence)):
index = 0
Move this file (as root) to /usr/bin/lightsequences.py . You can save yourself some
annoyance later by also setting it to be executable:
$ sudo chmod +x /usr/bin/lightsequences.py
You probably want to make this Python script run automatically when your Raspberry
Pi boots up. The way to do this is different between Pidora and Raspbian.
For Raspbian, you simply need to invoke this script from /etc/rc.local . Open that file
with a text editor (as root), and add this line directly above the line that says exit 0 :
python /usr/bin/lightsequences.py &
The use of the & command at the end of the line tells the Python script to run in the
background. This is important, because otherwise, rc.local would wait for it to finish
before proceeding. Since this script runs in an infinite loop, it would never proceed,
and your boot process would sit there waiting.
Pidora uses a different boot software ( systemd ), which does not use the rc.local
concept. As a result, you will need to create a new systemd service file for the Python
script. Copy this file (also in the topic's GitHub repository) to /usr/lib/systemd/
system/lightsequences.service (as root):
[Unit]
Description=Christmas Light Sequence Loop
[Service]
Type=simple
ExecStart=/usr/bin/python /usr/bin/lightsequences.py
[Install]
WantedBy=multi-user.target
Search WWH ::




Custom Search