import RPi.GPIO as GPIO
import time

# map SSR channel to GPIO output
channel_1 = 17
channel_2 = 27
channel_3 = 22
channel_4 = 23

def setup():
    """setup GPIOs"""
    GPIO.setmode(GPIO.BCM)
    GPIO.setup(channel_1, GPIO.OUT)
    GPIO.setup(channel_2, GPIO.OUT)
    GPIO.setup(channel_3, GPIO.OUT)
    GPIO.setup(channel_4, GPIO.OUT)


def motors_on(one,two,three,four):
    """turn motors on"""
    print('motors on')
    GPIO.output(one, GPIO.HIGH)
    GPIO.output(two, GPIO.HIGH)
    GPIO.output(three, GPIO.HIGH)
    GPIO.output(four, GPIO.HIGH)


def motors_off(one,two,three,four):
    """turn motors off"""
    print('motors off')
    GPIO.output(one, GPIO.LOW)
    GPIO.output(two, GPIO.LOW)
    GPIO.output(three, GPIO.LOW)
    GPIO.output(four, GPIO.LOW)


if __name__ == '__main__':
    try:
        setup()
        motors_on(channel_1,channel_2,channel_3,channel_4)
        time.sleep(10)
        motors_off(channel_1,channel_2,channel_3,channel_4)
        time.sleep(2)
        GPIO.cleanup()
    except KeyboardInterrupt: # exit gracefully
        motors_off(channel_1,channel_2,channel_3,channel_4)
        GPIO.cleanup()