Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 1297

Python • Program to blink 3 LEDs

$
0
0
Hi, I have created a program to blink 3 LED's in sequence. Im just sure if the hardware button is faulty or not. Can anyone share their views on the code?

Code:

import RPi.GPIO as GPIOimport timeLED1 = 16LED2 = 20LED3 = 21BUTTON = 13GPIO.setmode(GPIO.BCM)GPIO.setup(LED1, GPIO.OUT)GPIO.setup(LED2, GPIO.OUT)GPIO.setup(LED3, GPIO.OUT)GPIO.setup(BUTTON, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)while True:    for x in range(0,3):        while GPIO.input(BUTTON) == GPIO.LOW:            pass        if GPIO.input(BUTTON) == GPIO.HIGH and x == 0:            GPIO.output(LED1,GPIO.HIGH)            GPIO.output(LED2,GPIO.LOW)            GPIO.output(LED3,GPIO.LOW)            while GPIO.input(BUTTON) == GPIO.HIGH:                pass            while GPIO.input(BUTTON) == GPIO.LOW:                pass        elif GPIO.input(BUTTON) == GPIO.HIGH and x == 1:            GPIO.output(LED1,GPIO.LOW)            GPIO.output(LED2,GPIO.HIGH)            GPIO.output(LED3,GPIO.LOW)            while GPIO.input(BUTTON) == GPIO.HIGH:                pass            while GPIO.input(BUTTON) == GPIO.LOW:                pass        elif GPIO.input(BUTTON) == GPIO.HIGH and x == 2:            GPIO.output(LED1,GPIO.LOW)            GPIO.output(LED2,GPIO.LOW)            GPIO.output(LED3,GPIO.HIGH)            while GPIO.input(BUTTON) == GPIO.HIGH:               pass            while GPIO.input(BUTTON) == GPIO.LOW:               pass            GPIO.output(LED3,GPIO.LOW)                                                                                                                                                               

Statistics: Posted by fashe002 — Thu May 23, 2024 11:58 am



Viewing all articles
Browse latest Browse all 1297

Trending Articles