Traffic lights update

Now that I have my Raspberry Pi traffic light project auto running from start up.  To do this I had to set it so that the Raspberry Pi auto logins.  The process for doing this is described here.  Then edit .bash_profile so the programs I want to start are started up from there.  As I want to demonstrate this without the  use of keyboard, mouse or monitor I was faced with the issue of being able to properly shutdown the Pi.  I just wanted to start up the demo and be able to shut it down while in the field.

I have found the solution by adding a button to the project that shuts down the pi when pressed.

The Raspberry Pi  user guide (issue 1) page 197 has details of the actual circuit and code required to detect a button press.

I then had the issue of how to run both programs at the same time the solution here was to background the process then run the traffic lights program.

To do this I edited the .bash_profile text file and added the following

pi@raspberrypi:~$ cat .bash_profile
hostname -I
echo "hello, backgrounding shutdown process"
sudo python ./RaspberryPI/gpio/ &
echo "running traffic lights" 
sudo python ./RaspberryPI/gpio/

This starts up and then backgrounds the task, then starts the traffic lights program up.

so the code I used for the shutdown program is as follows

import RPi.GPIO as GPIO
import time
from time import sleep
import os
GPIO.setmode (GPIO.BOARD ); GPIO.setup(23, GPIO.IN) #sswitch
while True:
  input_value = GPIO.input(23)
  if input_value == False:
    print ("shuttimg dpwm pi")
    os.system("sudo shutdown -h now")
    while input_value == False:

I found this article to help me with the shutdown routine.

then my traffic lights code is here for completeness

import RPi.GPIO as GPIO
from time import sleep
GPIO.setmode (GPIO.BOARD ); GPIO.setup(11, GPIO.OUT) #red led
GPIO.setmode (GPIO.BOARD ); GPIO.setup(13, GPIO.OUT) #yellow led
GPIO.setmode (GPIO.BOARD ); GPIO.setup(19, GPIO.OUT) #green led
#turn off leds
#turn off leds
for x in off:
	GPIO.output (x, False)
i = 1
while i < 5:
	GPIO.output (11, True) # turn on red
	GPIO.output (13,True) # turn on amber
	GPIO.output (11, False) #turn off red
	GPIO.output (13, False) #turn off amber
	GPIO.output (19, True) #turn on green
	GPIO.output (19, False) #turn off green
	GPIO.output (13, True) # turn on amber
	GPIO.output(13, False) #turn off amber
	GPIO.output(11, True) #Turn on Red

This all works for me here,  there is room for a few tweaks somewhere. But this is for later.