Python gpiozero 模块,LED 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用gpiozero.LED

项目:EduKit1    作者:CamJam-EduKit    | 项目源码 | 文件源码
def startwalking():
    # Make the buzzer buzz on and off, half a second of
    # sound followed by half a second of silence
    print("Start walking")
    count = 1
    while count <= 4:
        print("Beep")
        buzzer.on()
        time.sleep(0.5)
        buzzer.off()
        time.sleep(0.5)
        count += 1


# Turn the buzzer off and wait for 2 seconds
# (If you have a second green 'pedestrian' LED, make it flash on and
# off for the two seconds)
项目:EduKit1    作者:CamJam-EduKit    | 项目源码 | 文件源码
def flashingambergreen():
    print("Flashing amber and green")
    red.off()
    green.off()

    iCount = 1
    while iCount <= 6:
        yellow.on()
        time.sleep(0.5)
        yellow.off()
        time.sleep(0.5)
        iCount += 1
    green.on()


# Flash the amber for one more second
# (Turn the green 'pedestrian' LED off and the red on)
项目:artwork    作者:shlinx    | 项目源码 | 文件源码
def control_led(self, on=True):
        led_pins = LED_COLORS[self.led_color_index]
        if on:
            print("Turning on LED for pins {}".format(led_pins))
            for pin in led_pins:
                pin_obj = self.led_pins[pin]
                pin_obj.on()
        else:
            print("Turning off LED for pins {}".format(led_pins))
            for pin in led_pins:
                pin_obj = self.led_pins[pin]
                pin_obj.off()
            self.led_color_index += 1
            try:
                LED_COLORS[self.led_color_index]
            except IndexError:
                self.led_color_index = 0
项目:EduKit1    作者:CamJam-EduKit    | 项目源码 | 文件源码
def startgreen():
    print("Green light on")
    green.on()
    yellow.off()
    red.off()


# Turn the green off and the amber on for 3 seconds
# ('Pedestrian' red LED stays lit)
项目:EduKit1    作者:CamJam-EduKit    | 项目源码 | 文件源码
def dontwalk():
    print("Don't walk")
    buzzer.off()


# Flash the amber on and off for 6 seconds
# (And the green 'pedestrian' LED too)
项目:4mics_hat    作者:respeaker    | 项目源码 | 文件源码
def __init__(self, pattern=AlexaLedPattern):
        self.pattern = pattern(show=self.show)

        self.dev = apa102.APA102(num_led=self.PIXELS_N)

        self.power = LED(5)
        self.power.on()

        self.queue = Queue.Queue()
        self.thread = threading.Thread(target=self._run)
        self.thread.daemon = True
        self.thread.start()

        self.last_direction = None
项目:artwork    作者:shlinx    | 项目源码 | 文件源码
def __init__(self, sensor_pin=4):
        self.pir = MotionSensor(sensor_pin)
        self.led_pins = {}
        self.count = int(time.time())
        self.pir.when_motion = self.on_when_motion
        self.pir.when_no_motion = self.on_when_no_motion
        self.audio_file_index = 0
        self.led_color_index = 0
        for pin in LED_PINS:
            self.led_pins[pin] = LED(pin)
        print('Artwork is watching motions...')
        pause()
项目:Prodigy_Bot    作者:akhilesh-k    | 项目源码 | 文件源码
def ledToggle():
  if led.is_lit:
    led.off()
    ledButton["text"]="Turn Your LED on"
  else:
    led.on()
    ledButton["text"]="Turn your LED off"
项目:garage-door    作者:denniskline    | 项目源码 | 文件源码
def __init__(self):
        self._ledGreen = LED(22)
        self._ledYellow = LED(27)
        self._ledRed = LED(17)
        pass
项目:EduKit1    作者:CamJam-EduKit    | 项目源码 | 文件源码
def startgreen():
    # Remember all code in the function is indented

# Turn the green off and the amber on for 3 seconds
# ('Pedestrian' red LED stays lit)
def steadyamber():
    # Remember all code in the function is indented

# Turn the amber off, and then the red on for 1 second
def steadyred():
    # Remember all code in the function is indented

# Sound the buzzer for 4 seconds
# (If you have the 'pedestrian' LEDs, turn the red off and green on)
def startwalking():
    # Make the buzzer buzz on and off, half a second of
    # sound followed by half a second of silence

# Turn the buzzer off and wait for 2 seconds
# (If you have a second green 'pedestrian' LED, make it flash on and
# off for the two seconds)
def dontwalk():
    # Remember all code in the function is indented

# Flash the amber on and off for 6 seconds
# (And the green 'pedestrian' LED too)
def flashingambergreen():
    # Remember all code in the function is indented

# Flash the amber for one more second
# (Turn the green 'pedestrian' LED off and the red on)
def flashingamber():
    # Remember all code in the function is indented

# Go through the traffic light sequence by calling each function
# one after the other.
def trafficlightqequence():
    # Remember all code in the function is indented

os.system('clear')  # Clears the terminal
print("Traffic Lights")
# Initialise the traffic lights
startgreen()

# Here is the loop that waits at lease 20 seconds before
# stopping the cars if the button has been pressed
while True:  # Loop around forever
    buttonnotpressed = True  # Button has not been pressed
    start = time.time()  # Records the current time
    while buttonnotpressed:  # While the button has not been pressed
        time.sleep(0.1)  # Wait for 0.1s
        if button.ispressed:  # If the button is pressed
            now = time.time()
            buttonnotpressed = False  # Button has been pressed
            if (now - start) <= 20:  # If under 20 seconds
                time.sleep(20 - (now - start))  # Wait until 20s is up
                trafficlightqequence()  # Run the traffic light sequence