def wrapper():
            # Setup
            i = Input(INPUT_PIN)
            o = Output(OUTPUT_PIN, active_low=output_active_low)

            passed = func(i, o)

            # Teardown
            i.disable()
            o.disable()

            return passed
        def wrapper():
            # Setup
            b = Button(INPUT_PIN)
            o = Output(OUTPUT_PIN, active_low=output_active_low)

            passed = func(b, o)

            # Teardown
            b.disable()
            o.disable()

            return passed
        def wrapper():
            # Setup
            i = Input(INPUT_PIN)
            o = Output(OUTPUT_PIN, active_low=output_active_low)

            passed = func(i, o)

            # Teardown
            i.disable()
            o.disable()

            return passed
        def wrapper():
            # Setup
            b = Button(INPUT_PIN)
            o = Output(OUTPUT_PIN, active_low=output_active_low)

            passed = func(b, o)

            # Teardown
            b.disable()
            o.disable()

            return passed
def _output_defaults():
    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

    DisablePin(OUTPUT_PIN)
    DisablePin(INPUT_PIN)
    return released_worked and pressed_worked
def board_rev():
    # Verify board_family is Raspberry Pi 2
    rev = Output.board_rev()
    known = rev in [0x0004, 0x0005, 0x0006, 0x0007, 0x0008, 0x0009, 
                    0x000d, 0x000e, 0x000f, 0x0010, 0x0011, 0x0012, 
                    0x1041, # Pi 2
                    0x2082, # Pi 3
                    ]
    print("Board rev: 0x{:04x}".format(rev))
    if not known:
        print("Board is not known.  Some tests may fail.")
    return known
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 _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 board_rev():
    # Verify board_family is Raspberry Pi 2
    rev = Output.board_rev()
    known = rev in [
        0x0004,
        0x0005,
        0x0006,
        0x0007,
        0x0008,
        0x0009,
        0x000d,
        0x000e,
        0x000f,
        0x0010,
        0x0011,
        0x0012,
        0x1041,  # Pi 2
        0x2082,  # Pi 3
    ]
    print("Board rev: 0x{:04x}".format(rev))
    if not known:
        print("Board is not known.  Some tests may fail.")
    return known
Пример #12
0
def on(pin_name):
    if pin_name in pin_io:
        pin_io[pin_name].disable()
    pin_io[pin_name] = Output(pins[pin_name])
    pin_io[pin_name].on()
Пример #13
0
from rstem.led_matrix import FrameBuffer, Sprite
from rstem.gpio import Output
import time
from random import random

fb = FrameBuffer([(0, 0, 90)])

outs = [
    Output(17),
    Output(27),
    Output(22),
    Output(23),
    Output(4),
    Output(14),
    Output(15),
    Output(18),
]

with open('scroller1.spr') as f:
    s1 = Sprite(f.read())
s1_width = s1.width
s1 += s1

with open('scroller2.spr') as f:
    s2 = Sprite(f.read())
s2_width = s2.width
s2 += s2

i = 0
i1 = 0
i2 = 0
Пример #14
0
#!/usr/bin/env python3
import rstem
from rstem.button import Button
from rstem.gpio import Output
from rstem.sound import Note
from random import randrange
import time

buttons = [Button(27), Button(23), Button(24), Button(22)]
lights = [Output(4), Output(18), Output(14), Output(15)]
notes = [Note('A'), Note('B'), Note('C'), Note('D')]
you_failed_note = Note('E2')
you_failed_note.volume = 1000

for note in notes:
    note.volume = 400

for light in lights:
    light.off()

play_order = []
failed = False
while not failed:
    play_order += [randrange(4)]

    # Play sequence
    for i in play_order:
        lights[i].on()
        notes[i].play(0.4).wait()
        lights[i].off()
        time.sleep(0.2)
Пример #15
0
# ##################################
# Import Modules and Initialize Game
# ##################################

from rstem.button import Button
from rstem.gpio import Output
from rstem.sound import Note
from random import randrange
import time
from itertools import cycle

buttons = [Button(14), Button(15), Button(23), Button(17)]
lights = [Output(4), Output(18), Output(24), Output(27)]
notes = [Note('C5'), Note('D5'), Note('E5'), Note('F5')]

you_failed_note = Note('E4')

light_cycle = cycle(lights)
while True:
    for b in buttons:
        b.presses()
    pressed = False
    prev_light = next(light_cycle)
    cur_light = next(light_cycle)
    while not pressed:
        prev_light.off()
        cur_light.on()
        prev_light = cur_light
        cur_light = next(light_cycle)

        for b in buttons:
Пример #16
0
# ##################################
# Import Modules and Initialize Game
# ##################################

from rstem.button import Button
from rstem.gpio import Output
from rstem.sound import Note
from random import randrange
import time

buttons = [Button(14), Button(15), Button(23), Button(17)]
lights = [Output(4, active_low=False), Output(18, active_low=False), Output(24, active_low=False), Output(27, active_low=False)]
notes = [Note('C'), Note('D'), Note('E'), Note('F')]

you_failed_note = Note('E3')

while True:
    button_pressed = 0
    count = 0
    while not button_pressed:
        for light in lights:
            if count % 15:
                light.off()
            else:
                light.on()
        for button in buttons:
            button_pressed += button.presses()
        count += 1
        time.sleep(0.2)

    for light in lights:
Пример #17
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()
#!/usr/bin/python3
from rstem.led_matrix import FrameBuffer, Text
from rstem.gpio import Output
import traceback
import sys
import time

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)
def verify_cpu(i, o):
    rev = Output.board_rev()
    max_cpu = 20 if rev < 0x1000 else 10;
    return testing.verify_cpu(max_cpu)
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 verify_cpu(i, o):
    rev = Output.board_rev()
    max_cpu = 20 if rev < 0x1000 else 10
    return testing.verify_cpu(max_cpu)
Пример #22
0
#!/usr/bin/env python3
import rstem
from rstem.gpio import Output
import time

light = Output(4)

lights.on()
time.sleep(1)
lights.off()
Пример #23
0
#!/usr/bin/env python3
import rstem
from rstem.gpio import Output
import time

lights = [Output(4), Output(27), Output(17), Output(25)]

for light in lights:
    light.off()

lights.on()
time.sleep(1)
lights.off()