# code adapted from Dagan Martinez's work # https://github.com/Property404/lionchief-controller # sensor code by Joseph Rampolla import RPi.GPIO as GPIO import time GPIO.setwarnings(False) import RPi.GPIO as GPIO from time import sleep GPIO.setmode(GPIO.BOARD) #uses board numbering GPIO.setup(29, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO 5 sensor 2 GPIO.setup(31, GPIO.IN, pull_up_down=GPIO.PUD_UP) # GPIO 6 sensor 1 GPIO.setup(7, GPIO.OUT) # GPIO 4 for relay trigger turnout from lc import LionChief import time chief = LionChief("44:A6:E5:3E:79:45") chief.set_bell_pitch(1) chief.speak() time.sleep(3.5) # Gradually start or stop def ramp(start_speed, end_speed): speed = start_speed while speed != end_speed: chief.set_speed(speed) if speed > end_speed: speed -= 1 else: speed += 1 time.sleep(.2) chief.set_speed(end_speed) while True: # Time to go chief.set_horn(True) time.sleep(0.75) chief.set_horn(False) chief.set_reverse(False) ramp(0, 12) time.sleep(15) #change number to desired delay while True: if GPIO.input(31) == GPIO.LOW: # waits for sensor 1 to trigger # relay for O27 turnout GPIO.output(7, 1) # set GPIO24 to 1/GPIO.HIGH/True -- throws turnout sleep(0.5) # wait half a second GPIO.output(7, 0) # set GPIO24 to 0/GPIO.LOW/False sleep(0.5) # wait half a second break chief.set_reverse(True) ramp(0,8) chief.set_horn(True) time.sleep(0.75) chief.set_horn(False) while True: if GPIO.input(29) == GPIO.LOW: # waits for sensor 2 to trigger break # This is our stop chief.set_bell(True) time.sleep(1) ramp(6,0) time.sleep(.1) chief.set_bell(False) time.sleep(18) GPIO.cleanup
Please refer to hobby reference materials for correct and safe use information regarding these and all electronic circuits. These diagrams are intended to explain how things were accomplished in theory, but it is the responsibility of the individual to locate precise information regarding electrical circuits, materials, ratings of components, etc. Do not attempt these hobby projects, or any electrical project, if you don't have the necessary skills and experience.