Python gpiozero.LED Examples

The following are 15 code examples of gpiozero.LED(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module gpiozero , or try the search function .
Example #1
Source File: binaryio.py    From bacpypes with MIT License 6 votes vote down vote up
def ReadProperty(self, obj, arrayIndex=None):
        if _debug:
            BOPresentValue._debug("ReadProperty %r arrayIndex=%r", obj, arrayIndex)

        # access an array
        if arrayIndex is not None:
            raise ExecutionError(
                errorClass="property", errorCode="propertyIsNotAnArray"
            )
        

        ###TODO: obj._led is the LED object
        if _debug:
            BOPresentValue._debug("    - read led: %r", obj._led)
        
        if obj._led.value == 1:
            return "active"
        else:
            return "inactive" 
Example #2
Source File: 7-TrafficLights-solution.py    From EduKit1 with MIT License 6 votes vote down vote up
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) 
Example #3
Source File: 7-TrafficLights-solution.py    From EduKit1 with MIT License 6 votes vote down vote up
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) 
Example #4
Source File: pureGPIO.py    From HermesLedControl with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, numLeds, pinout, activeHigh):
		super(PureGPIO, self).__init__(numLeds)

		if len(pinout) != numLeds:
			raise InterfaceInitError('Pure GPIO number of led versus pinout declaration missmatch')

		self._pinout 		= pinout
		self._activeHigh 	= activeHigh
		self._image 		= self._newArray()

		self._leds 		= []
		for pin in self._pinout:
			self._leds.append(LED(pin=pin, active_high=activeHigh, initial_value=False)) 
Example #5
Source File: apa102.py    From HermesLedControl with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, hardware, global_brightness=AAPA102.MAX_BRIGHTNESS, order='rgb', bus=0, device=1, max_speed_hz=8000000, endFrame=255):
		super(APA102, self).__init__(hardware['numberOfLeds'])
		self._leds  = AAPA102(hardware['numberOfLeds'], global_brightness=global_brightness, order=order, bus=bus, device=device, max_speed_hz=max_speed_hz, endFrame=endFrame)

		try:
			self._power = LED(5)
		except:
			try:
				self._power = mraa.Gpio(5)
				self._power.dir(mraa.DIR_OUT)
			except Exception as e:
				self._logger.info('Device not using gpiozero or mraa, ignore power: {}'.format(e))

		self._hardware = hardware
		self._src = None
		if hardware.get('doa'):
			self._logger.info('Hardware is DOA capable')
			from libraries.seeedstudios.channel_picker import ChannelPicker
			from libraries.seeedstudios.source import Source

			lib = importlib.import_module('libraries.seeedstudios.' + hardware['doa'])
			klass = getattr(lib, 'DOA')

			self._src = Source(rate=hardware['rate'], channels=hardware['channels'])
			ch0 = ChannelPicker(channels=self._src.channels, pick=0)

			self._doa = klass(rate=hardware['rate'])
			self._src.link(ch0)
			self._src.link(self._doa) 
Example #6
Source File: binaryio.py    From bacpypes with MIT License 5 votes vote down vote up
def __init__(self, led_id, **kwargs):
        if _debug:
            RPiBinaryOutput._debug("__init__ %r %r", led_id, kwargs)
        BinaryOutputObject.__init__(self, **kwargs)

        # make an LED object
        self._led = LED(led_id)


#
#   __main__
# 
Example #7
Source File: __init__.py    From photobooth with GNU Affero General Public License v3.0 5 votes vote down vote up
def __init__(self):

        super().__init__()

        import gpiozero
        self.LED = gpiozero.LED
        self.RGBLED = gpiozero.RGBLED
        self.Button = gpiozero.Button
        self.GPIOPinInUse = gpiozero.GPIOPinInUse

        self._buttons = []
        self._lamps = []
        self._rgb = [] 
Example #8
Source File: __init__.py    From photobooth with GNU Affero General Public License v3.0 5 votes vote down vote up
def setLamp(self, bcm_pin):

        try:
            self._lamps.append(self.LED(bcm_pin))
            return len(self._lamps) - 1
        except self.GPIOPinInUse:
            logging.error('Pin {} already in use!'.format(bcm_pin))
            return None 
Example #9
Source File: ch_16_web_control.py    From raspberrypi_cookbook_ed3 with MIT License 5 votes vote down vote up
def html_for_led(led_number):
    i = str(led_number)
    result = " <input type='button' onClick='changed(" + i + ")' value='LED " + i + "'/>"
    return result 
Example #10
Source File: 7-TrafficLights-solution.py    From EduKit1 with MIT License 5 votes vote down vote up
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) 
Example #11
Source File: 7-TrafficLights-solution.py    From EduKit1 with MIT License 5 votes vote down vote up
def dontwalk():
    print("Don't walk")
    buzzer.off()


# Flash the amber on and off for 6 seconds
# (And the green 'pedestrian' LED too) 
Example #12
Source File: cerebro_utils.py    From aws-builders-fair-projects with Apache License 2.0 5 votes vote down vote up
def process_accept_effects(selfie_mode=False, image_path='', device_id=None):

    process_accept_effects_logger = logging.getLogger('cerebro_utils.process_accept_effects')

    if not test_environment:
        led = LED(config.__GREEN_LED__)
        led.on()

    audio_prompt = "Excellent! Seems that you like this effect. Now, lets upload this selfie ..."

    speech_file_path = generate_audio(speech_text=audio_prompt, filename="like_this_text.mp3")
    process_accept_effects_logger.info("Generated Audio now. Playing audio next ...")
    play_audio(file_path=speech_file_path)
    process_accept_effects_logger.info("Audio played. Done!")

    image_path = "%s/%s.jpg" % (config.__CEREBRO_MEDIA_DIR__, "filtered_image_effects")

    process_accept_effects_logger.info("Uploading the selfie now ...")
    upload_image(image_path=image_path)
    process_accept_effects_logger.info("Selfie was uploaded now!")

    profile_prompt = "Selfie was uploaded with image effects!"

    speech_file_path = generate_audio(speech_text=profile_prompt, filename="uploaded_with_effects.mp3")
    process_accept_effects_logger.info("Generated Audio now. Playing audio next ...")
    play_audio(file_path=speech_file_path)
    process_accept_effects_logger.info("Audio played. Done!")

    if not test_environment:
        led.off()

    process_accept_effects_logger.info("Completed the accept of the effects and uploaded. done!")
    
    return True 
Example #13
Source File: indicator.py    From GassistPi with GNU General Public License v3.0 5 votes vote down vote up
def __init__(self, pattern=GoogleHomeLedPattern):
        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.t4 = threading.Thread(target=self._run)
        self.t4.daemon = True
        self.t4.start()
        self.last_direction = None 
Example #14
Source File: binaryio.py    From bacpypes with MIT License 4 votes vote down vote up
def main():
    # parse the command line arguments
    args = ConfigArgumentParser(description=__doc__).parse_args()

    if _debug:
        _log.debug("initialization")
    if _debug:
        _log.debug("    - args: %r", args)

    # make a device object
    this_device = LocalDeviceObject(
        objectName=args.ini.objectname,
        objectIdentifier=("device", int(args.ini.objectidentifier)),
        maxApduLengthAccepted=int(args.ini.maxapdulengthaccepted),
        segmentationSupported=args.ini.segmentationsupported,
        vendorIdentifier=int(args.ini.vendoridentifier),
    )

    # make a sample application
    this_application = BIPSimpleApplication(this_device, args.ini.address)

    # make the buttons
    for button_id, bio_id in button_list:
        bio = RPiBinaryInput(
            button_id,
            objectIdentifier=("binaryInput", bio_id),
            objectName="Button-%d" % (button_id,),
        )
        _log.debug("    - bio: %r", bio)
        this_application.add_object(bio)

    # make the LEDs
    for led_id, boo_id in led_list:
        boo = RPiBinaryOutput(
            led_id,
            objectIdentifier=("binaryOutput", boo_id),
            objectName="LED-%d" % (led_id,),
        )
        _log.debug("    - boo: %r", boo)
        this_application.add_object(boo)

    _log.debug("running")

    run()

    _log.debug("fini") 
Example #15
Source File: 7-TrafficLights.py    From EduKit1 with MIT License 4 votes vote down vote up
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