import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BCM) # GPIO Numbers instead of board numbers RELAIS_1_GPIO = 27 GPIO.setup(RELAIS_1_GPIO, GPIO.OUT) # GPIO Assign mode # here you would put all your code for setting up GPIO, # we'll cover that tomorrow # initial values of variables etc... counter = 0 try: # here you put your main loop or block of code while True: # count up to 9000000 - takes ~20s time.sleep(3) print ("Hellooooo") if counter % 2 ==0: GPIO.output(RELAIS_1_GPIO, GPIO.LOW) # out else: GPIO.output(RELAIS_1_GPIO, GPIO.HIGH) # out counter += 1 print ("Target reached: %d" % counter) except KeyboardInterrupt: # here you put any code you want to run before the program # exits when you press CTRL+C print ("\n", counter) # print value of counter except: # this catches ALL other exceptions including errors. # You won't get any error messages for debugging # so only use it once your code is working print ("Other error or exception occurred!") finally: GPIO.cleanup() # this ensures a clean exit