Coursera assignment 3

Coursera assignment 3



import time
import RPi.GPIO as GPIO

GPIO.setmode(GPIO.BOARD)

ledPin = 11
buttonPin = 13

GPIO.setup(ledPin, GPIO.OUT)
GPIO.setup(buttonPin, GPIO.IN, pull_up_down = GPIO.PUD_UP)

try:
    while True:
        if( GPIO.input(buttonPin) ):
            GPIO.output(ledPin, GPIO.HIGH)    
        else:
            GPIO.output(ledPin, GPIO.HIGH)
            time.sleep(0.25)
            GPIO.output(ledPin, GPIO.LOW)
            time.sleep(0.25)
    
finally:
    GPIO.output(ledPin, GPIO.LOW)
    GPIO.cleanup()
    print("\nStopped")
    exit()



Comments

Popular posts from this blog

4.Sort an array of 0's, 1's & 2's.

1. Reverse

3. Height of Binary tree