Tuesday, April 30, 2019

Flowing LED Lights Raspberry Pi Experiments Python for practise

Lab 1c

Flowing LED Lights

CIRCUIT DIAGRAM:

Note the Image shows how LED is connected we will only use 3 or 4 LED just for understanding Purpose

In [1]:
%%html
<img src="https://www.w3schools.com/nodejs/img_raspberrypi3_led_flowing.png" , width=600, height=300>

Code

In [ ]:
import RPi.GPIO as GPIO
import time

pins = [11, 12, 13, 15]
GPIO.setmode(GPIO.BOARD)        # to use Raspberry Pi board pin numbers

for pin in pins:
    GPIO.setup(pin, GPIO.OUT)   # Set all pins mode as output
def setup():
    try:
        loop()
    except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
        destroy()

def loop():
    while True:
        for pin in pins:
            GPIO.output(pin, GPIO.LOW)
            time.sleep(0.05)
            GPIO.output(pin, GPIO.HIGH)
        for pin in reversed(pins):
            GPIO.output(pin, GPIO.LOW)
            time.sleep(0.05)
            GPIO.output(pin, GPIO.HIGH)

def destroy():
    for pin in pins:
        GPIO.output(pin, GPIO.HIGH)
    GPIO.cleanup()                     # Release resource


setup()                              #call the method setup()
In [ ]:
 
In [ ]:
 

No comments:

Post a Comment

Develop Full Text Search (Semantics Search) with Postgres (PGVector) and Python Hands on Lab

final-notebook Develop Full Text Search (Semantics Search) with Postgres (PGVector)...