Python Forum
functional LEDs in an array or list? // RPi user
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
functional LEDs in an array or list? // RPi user
#1
Hi! Total programming noob (not just in Python) here trying to make his code a bit shorter and more readable.

I'm trying to put functional LEDs in an array or list to make it easier to turn two or more on at the same time. However it ends in:
Error:
AttributeError: 'list' object has no attribute 'on'
The code for it is:
import time
from gpiozero import Buzzer
from gpiozero import LED

red = LED(2)
yellow = LED(3)
green = LED(4)
blue = LED(14)
buzzer = Buzzer(15)
leds = [red, yellow, green, blue]

password = int(input('xxxxxxxx: '))
if password != xxxx:
    print('xxxxxxxx')
    for i in range(3):
        red.on()
        buzzer.on()
        time.sleep(0.2)
        red.off()
        buzzer.off()
        time.sleep(0.2)
elif password == xxxx:
    print('xxxxxx')
    for i in range(3):
        leds.on()
        buzzer.on()
        time.sleep(0.2)
        leds.off()
        buzzer.off()
        time.sleep(0.2)
    green.on()
The error is in line 25 and 28. I tried searching for a solution or how to implement it correctly, however any array or list functon i find uses it for text data.

Am i overthinking it or missing something obvious?
Reply


Messages In This Thread
functional LEDs in an array or list? // RPi user - by Doczu - Aug-21-2022, 03:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  user input values into list of lists tauros73 3 1,176 Dec-29-2022, 05:54 PM
Last Post: deanhystad
Question How to let the user add 'None' to an specific array in a dictionary? noahverner1995 4 1,882 Dec-26-2021, 10:03 AM
Last Post: noahverner1995
  Stuck in functional proggaming haze hammer 2 1,476 Oct-27-2021, 02:07 PM
Last Post: hammer
  Make these LEDs stay on duckredbeard 5 3,078 Apr-08-2021, 10:26 PM
Last Post: duckredbeard
  Looking for a way to loop until user enters from a list? PythonW19 7 3,548 Mar-21-2021, 08:56 PM
Last Post: PythonW19
  OOP vs functional - - elaborate turn based RPG game (Derek Banas Udemy course again) Drone4four 6 4,117 Mar-14-2021, 08:38 AM
Last Post: ndc85430
  Calculating surface area - - OOP or functional? Derek Banas Udemy course Drone4four 5 3,738 Mar-13-2021, 06:22 AM
Last Post: buran
  User input/picking from a list AnunnakiKungFu 2 2,413 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
  LIST or ARRAY Comparison and change of value nio74maz 0 1,744 Dec-21-2020, 05:52 PM
Last Post: nio74maz
Question Reset list if user regrets Gilush 1 2,133 Dec-05-2020, 10:55 AM
Last Post: Gilush

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020