#! /user/bin/env python
# tsignal2.py

import RPi.GPIO as GPIO
import time

#GPIO.cleanup()

GPIO.setmode( GPIO.BCM )
GPIO.setup(  4, GPIO.OUT )
GPIO.setup( 17, GPIO.OUT )
GPIO.setup( 27, GPIO.OUT )
GPIO.setup( 22, GPIO.IN )

GPIO.output( 4, GPIO.LOW )
GPIO.output( 17, GPIO.LOW )
GPIO.output( 27, GPIO.LOW )

while True:
    if GPIO.input(22)==GPIO.LOW:
        GPIO.output( 4, GPIO.HIGH )
        time.sleep( 2 )
        GPIO.output( 4, GPIO.LOW )

        GPIO.output( 17, GPIO.HIGH )
        time.sleep( 0.5 )
        GPIO.output( 17, GPIO.LOW )

        GPIO.output( 27, GPIO.HIGH )
        time.sleep( 2 )
        GPIO.output( 27, GPIO.LOW )
    else:
        GPIO.output( 4, GPIO.HIGH )
        time.sleep( 0.2 )
        GPIO.output( 4, GPIO.LOW )

        GPIO.output( 17, GPIO.HIGH )
        time.sleep( 0.05 )
        GPIO.output( 17, GPIO.LOW )

        GPIO.output( 27, GPIO.HIGH )
        time.sleep( 0.2 )
        GPIO.output( 27, GPIO.LOW )