How to use the gpiozero.LED function in gpiozero

To help you get started, we’ve selected a few gpiozero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gpiozero / gpiozero / tests / test_tools.py View on Github external
def test_set_source_by_device(mock_factory):
    with LED(2) as led, Button(3) as btn:
        led.source_delay = 0
        assert not led.value
        assert not btn.value
        led.source = btn
        sleep(epsilon)
        assert not led.value
        assert not btn.value
        btn.pin.drive_low()
        sleep(epsilon)
        assert led.value
        assert btn.value
github kevinwlu / iot / lesson3 / led.py View on Github external
from gpiozero import LED
from time import sleep

green = LED(18)

while True:
    try:
        green.on()
        sleep(2)
        green.off()
        sleep(2)
    except KeyboardInterrupt:
        exit()
github gpiozero / gpiozero / docs / examples / mock_demo.py View on Github external
from gpiozero.pins.mock import MockFactory
from gpiozero import Device, Button, LED
from time import sleep

# Set the default pin factory to a mock factory
Device.pin_factory = MockFactory()

# Construct a couple of devices attached to mock pins 16 and 17, and link the
# devices
led = LED(17)
btn = Button(16)
led.source = btn.values

# Here the button isn't "pushed" so the LED's value should be False
print(led.value)

# Get a reference to mock pin 16 (used by the button)
btn_pin = Device.pin_factory.pin(16)

# Drive the pin low (this is what would happen electrically when the button is
# pushed)
btn_pin.drive_low()
sleep(0.1) # give source some time to re-read the button state
print(led.value)

btn_pin.drive_high()
github Hecsall / Raspberry-MIDI-Controller / midi_controller.py View on Github external
def main():
  logging.basicConfig(format="%(name)s: %(levelname)s - %(message)s", level=logging.INFO)

  midiout, port_name = open_midioutput(1)

  # Init FootController
  footcontroller = FootController(midiout)

  # A status indicator, will light up after the FootController is initialized,
  # to let you know that now it's able to send midi signals
  statusLed = LED(18)
  statusLed.on()

  log.info("Entering main loop. Press Control-C to exit.")

  try:
    while True:
    
      # Hold behaviour (Press=ON, Release=OFF)
      # footcontroller.btn4.when_pressed = lambda : footcontroller.sendMIDI(type=CONTROLLER_CHANGE, channel=0x40, value=64)
      # footcontroller.btn4.when_released = lambda : footcontroller.sendMIDI(type=CONTROLLER_CHANGE, channel=0x40, value=0)
      
      footcontroller.btn5.when_pressed = lambda : footcontroller.sendMIDI(type=CONTROLLER_CHANGE, channel=0x50, value=100)
      footcontroller.btn5.when_released = lambda : footcontroller.sendMIDI(type=CONTROLLER_CHANGE, channel=0x50, value=0)
      footcontroller.btn6.when_pressed = lambda : footcontroller.sendMIDI(type=CONTROLLER_CHANGE, channel=0x51, value=100)
      footcontroller.btn6.when_released = lambda : footcontroller.sendMIDI(type=CONTROLLER_CHANGE, channel=0x51, value=0)
      footcontroller.btn13.when_pressed = lambda : footcontroller.sendMIDI(type=CONTROLLER_CHANGE, channel=0x52, value=100)
github ukBaz / python-bluezero / examples / level10 / microbit_button.py View on Github external
"""
import argparse
import dbus
from time import sleep

from gpiozero import LED
from gpiozero import Buzzer

from bluezero import constants
from bluezero import tools
from bluezero import adapter

# constants
led1 = LED(22)
led2 = LED(23)
led3 = LED(24)
buzz = Buzzer(5)
BEEP_TIME = 0.25


class microbit:
    """
    Class to introspect Bluez to find the paths for required UUIDs
    """
    def __init__(self, address):
        self.bus = dbus.SystemBus()
        self.address = address
        # Device Information
        self.device_path = tools.get_dbus_path(constants.DEVICE_INTERFACE,
                                               'Address',
                                               self.address)[0]
        self.remote_device_obj = self.bus.get_object(
github recantha / musicbox / musicbox.py View on Github external
# Test procedure for the keyboard buttons
test_buttons = False
if test_buttons:
	while True:
		print("Tbot:{}/Ttop:{}/Trih:{}/Idx:{}/Mid:{}/Rng:{}/Pnk:{}".format(thumb_bottom.value, thumb_top.value, thumb_right.value, index_finger.value, middle_finger.value, ring_finger.value, pinky_finger.value))
		time.sleep(0.2)


# Define potentiometers
pot0 = MCP3008(channel=2)
pot1 = MCP3008(channel=1)
pot2 = MCP3008(channel=0)

# Turn the light on
led_purple = LED(24)
led_purple.on()

def play_note(note):
	fs.noteon(0, note, 60)

def octave_up():
    global octave
    if octave < octaves:
        octave += 1
        print('Selected Octave: {}'.format(octave))

def octave_down():
    global octave
    if octave > 0:
        octave -= 1
        print('Selected Octave: {}'.format(octave))
github gpiozero / gpiozero / docs / examples / led_travis.py View on Github external
from travispy import TravisPy
from gpiozero import LED
from gpiozero.tools import negated
from time import sleep
from signal import pause

def build_passed(repo):
    t = TravisPy()
    r = t.repo(repo)
    while True:
        yield r.last_build_state == 'passed'

red = LED(12)
green = LED(16)

green.source = build_passed('gpiozero/gpiozero')
green.source_delay = 60 * 5  # check every 5 minutes
red.source = negated(green)

pause()
github google / aiyprojects-raspbian / src / examples / gpiozero / bonnet_button.py View on Github external
"""Example code that demonstrates using a button connected through the hat.

The button uses a hat pin through the sysfs driver illustrating the edge
detection polling.

The demo will light up the on board LED whenever PIN_D is drawn high.
"""
from signal import pause
from gpiozero import Button
from gpiozero import LED
from aiy.pins import LED_1
from aiy.pins import PIN_D


# Set up a gpiozero LED using the first onboard LED on the vision hat.
led = LED(LED_1)
# Set up a gpiozero Button using the 4th pin on the vision hat expansion.
button = Button(PIN_D)

# When the button is pressed, call the led.on() function (turn the led on)
button.when_pressed = led.on
# When the button is released, call the led.off() function (turn the led off)
button.when_released = led.off

# Wait for the user to kill the example.
pause()
github j-chimienti / pollofeed / src / pi / pollofeed.py View on Github external
def activate(pin=18, seconds=7, timeout=0):

    try:
        vending_machine = LED(pin)
        if timeout > 0:
            time.sleep(timeout)
        start = time.time()
        vending_machine.on()
        print("LED on")
        time.sleep(seconds)
        print("LED off")
        vending_machine.off()
        end = time.time()
        print('LED time:', end - start)
        return True
    except Exception:
        return False