Пример #1
0
 def test_Write_DoesnotShowError(self):
   with LEDs() as LED:       
       LED.write()                         # The default values are - led: led0, value_to_set = True.
       time.sleep(1)
       LED.write(led=Led.LED1)             # The default 'value_to_set' is True
       time.sleep(1)
       LED.write(Led.LED2, True)
       time.sleep(1)
       LED.write(Led.LED3, True)
       time.sleep(1)
       LED.write(value_to_set=False)       # the default 'led' is 'led0'
       time.sleep(1)
       LED.write(Led.LED1, False)
       time.sleep(1)
       LED.write(Led.LED2, False)
       time.sleep(1)
       LED.write(Led.LED3, False)
       time.sleep(1)
Пример #2
0
def irq_handler():
    """
    irq_handler contains the code you want to execute when the interrupt
    occurs. Define your own callback function here by rewriting the code. We
    make an LED flash in this example.
    """
    # open an LED session
    with LEDs() as LED:
        # specify the LED which you want to control
        led = Led.LED1
        # specify the LED status
        led_on_off = True
        # writes values 10 times, which makes LED1 flash for 3 seconds
        for x in range(0, 10):
            # turn LED0 on or off
            LED.write(led, led_on_off)
            # add a short delay
            time.sleep(0.3)
            # if the LED is on, set the parameter to off
            # if the LED is off, set the parameter to on
            led_on_off = not led_on_off
Пример #3
0
interrupt_type_falling = False
# specify the number of edges of the signal that must occur for this
# program to register an interrupt. For example, when
# interrupt_type_rising is True and edge_count is 1, an interrupt occurs
# when the DIO channel receives one rising edge
edge_count = 1
# configure a digital input interrupt session
with DIIRQ(irq_channel,
                      irq_handler,
                      irq_number,
                      timeout,
                      interrupt_type_rising,
                      interrupt_type_falling,
                      edge_count) as DI_IRQ:
    # open the LED session
    LED = LEDs()
    # specify the LED which you want to control
    led = Led.LED0
    # specify the LED status
    led_on_off = True

    # create a thread to wait for the interrupt
    irq_thread = threading.Thread(target=DI_IRQ.wait)
    irq_thread.start()

    # writes values 50 times, which makes LED0 flash for 25 seconds
    for x in range(0, 50):
        # turn LED0 on or off
        LED.write(led, led_on_off)
        # add a short delay
        time.sleep(0.5)
Пример #4
0
precisely timed, and is controlled by a software delay.

This example uses:
    LED0.

Hardware setup:
    No hardware is needed.

Result:
    LED0 flashes for 5 seconds.
"""
import time
from nielvis import LEDs, Led

# configure an LED session
with LEDs() as LED:
    # specify the LED which you want to control
    led = Led.LED0
    # specify the LED status
    led_on_off = True
    # writes values 10 times, which makes LED0 flash for 5 seconds
    for x in range(0, 10):
        # turn LED0 on or off
        # the first parameter of the write function specifies which LED to
        # write to. The second parameter specifies the status of the LED, which
        # should be either True or False
        LED.write(led, led_on_off)
        # add a short delay
        time.sleep(0.5)
        # if the LED is on, set the parameter to off
        # if the LED is off, set the parameter to on