def _test_output_defaults_with_input():
    i = Input(INPUT_PIN)
    o = Output(OUTPUT_PIN) # default is active low!

    o.off() # HIGH
    time.sleep(MINIMUM_INPUT_PERIOD)
    high_worked = i.is_on()
    o.on() # LOW
    time.sleep(MINIMUM_INPUT_PERIOD)
    low_worked = i.is_off()

    i.disable()
    o.disable()
    return high_worked and low_worked
def _test_output_defaults_with_button():
    b = Button(INPUT_PIN)
    o = Output(OUTPUT_PIN) # default is active low!

    o.off() # HIGH
    time.sleep(MINIMUM_BUTTON_PRESS_PERIOD)
    released_worked = b.is_released() # Released button is HIGH
    o.on() # LOW
    time.sleep(MINIMUM_BUTTON_PRESS_PERIOD)
    pressed_worked = b.is_pressed() # PRESSED button is LOW

    b.disable()
    o.disable()
    return released_worked and pressed_worked
def _test_output_defaults_with_input():
    i = Input(INPUT_PIN)
    o = Output(OUTPUT_PIN)  # default is active low!

    o.off()  # HIGH
    time.sleep(MINIMUM_INPUT_PERIOD)
    high_worked = i.is_on()
    o.on()  # LOW
    time.sleep(MINIMUM_INPUT_PERIOD)
    low_worked = i.is_off()

    i.disable()
    o.disable()
    return high_worked and low_worked
def _test_output_defaults_with_button():
    b = Button(INPUT_PIN)
    o = Output(OUTPUT_PIN)  # default is active low!

    o.off()  # HIGH
    time.sleep(MINIMUM_BUTTON_PRESS_PERIOD)
    released_worked = b.is_released()  # Released button is HIGH
    o.on()  # LOW
    time.sleep(MINIMUM_BUTTON_PRESS_PERIOD)
    pressed_worked = b.is_pressed()  # PRESSED button is LOW

    b.disable()
    o.disable()
    return released_worked and pressed_worked
def input_pull_test(pull, stayed_on, stayed_off, configure=False):
    for n in range(5):
        if configure:
            i = Input(INPUT_PIN)
            i.configure(pull=pull)
        else:
            i = Input(INPUT_PIN, pull=pull)
        o = Output(OUTPUT_PIN, active_low=False)
        o.on()
        o.disable()
        actually_stayed_on = i.is_on()
        o = Output(OUTPUT_PIN, active_low=False)
        o.off()
        o.disable()
        actually_stayed_off = i.is_off()
        i.disable()
        if stayed_on == actually_stayed_on and stayed_off == actually_stayed_off:
            return True
        time.sleep(0.5)
        print("FAILED, RETRYING...")
    print("TOO MANY RETRIES!")
    return False
def input_pull_test(pull, stayed_on, stayed_off, configure=False):
    for n in range(5):
        if configure:
            i = Input(INPUT_PIN)
            i.configure(pull=pull)
        else:
            i = Input(INPUT_PIN, pull=pull)
        o = Output(OUTPUT_PIN, active_low=False)
        o.on()
        o.disable()
        actually_stayed_on = i.is_on()
        o = Output(OUTPUT_PIN, active_low=False)
        o.off()
        o.disable()
        actually_stayed_off = i.is_off()
        i.disable()
        if stayed_on == actually_stayed_on and stayed_off == actually_stayed_off:
            return True
        time.sleep(0.5)
        print("FAILED, RETRYING...")
    print("TOO MANY RETRIES!")
    return False
예제 #7
0
import mido
from rstem.button import Button
from rstem.gpio import Output

output = mido.open_output('X18/XR18 MIDI 1')
button = Button(4)
clean_led = Output(2)
distorted_led = Output(22)

output.send(mido.Message('control_change', channel=1))
output.send(mido.Message('control_change', channel=1, control=1, value=127))
distorted = False
clean_led.on()
distorted_led.off()
while True:
    if button.presses():
        if distorted == True:
            output.send(mido.Message('control_change', channel=1))
            output.send(
                mido.Message('control_change', channel=1, control=1,
                             value=127))
            distorted = False
            clean_led.on()
            distorted_led.off()
        elif distorted == False:
            output.send(mido.Message('control_change', channel=1, value=127))
            output.send(mido.Message('control_change', channel=1, control=1))
            distorted = True
            clean_led.off()
            distorted_led.on()
led = Output(14)

while True:
    num_uuts = 0
    on = False
    start = time.time()
    while num_uuts <= 2 or num_uuts >= 12:
        try:
            num_uuts = FrameBuffer.detect()
        except:
            num_uuts = 0

        if on:
            led.on()
        else:
            led.off()

        elapsed = time.time() - start
        if on and elapsed > 0.3 or not on and elapsed > 2:
            on = not on
            start = time.time()

        time.sleep(0.05)

    fb_spec = [(8*x,0,0) for x in range(num_uuts)]
    fb = FrameBuffer(fb_spec)

    digits = [Text(str(i)) for i in range(10)]

    def endcaps():
        fb.erase()