Example #1
0
        # the "rtc" (real-time clock) value of the last pressed key
        # should tell us how long the user took to press all of the
        # buttons
        last_press = keyevents[-1].rtc
        print "correct (%dms)" % last_press
        flash(usbbox)
    else:
        print "user said:", " ".join(
            [BUTTON_COLORS[event.key_code] for event in keyevents])
        print "wrong"
        flash(usbbox, rate=0.25, count=3)

    return correct


usbbox = USBBox()

print "Simon Says"
print "consists of several rounds of sequences being shown:"
print "1) LEDs will flash on box"
print "2) a sequence of LEDs will be shown"
print "3) after the sequence finishes the LEDs will flash again"
print "4) enter in the sequence previously shown (press the buttons that match the LEDs)"
print "5) if you get it right the LEDs will flash once and it'll repeat the cycle (with one more item to remember)"
print "6) if you get it wrong the LEDs will flash three times and you'll be asked if you want to play a new game"

# use logset so that 1 turns LED on and 0 turn LED off
usbbox.leds.logic = 0xFF
# and turn off the LEDs
usbbox.leds.state = 0x00
# ensure loop back isn't set
Example #2
0
from __future__ import print_function
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
# vi: set ft=python sts=4 ts=4 sw=4 et:
from ioLabs import USBBox

usbbox = USBBox()

usbbox.serial.write('testing hello world')

while True:
    bytes = usbbox.serial.read()
    if bytes:
        print(bytes)
Example #3
0
        # as we reset the clock after the lights went out
        # the "rtc" (real-time clock) value of the last pressed key
        # should tell us how long the user took to press all of the
        # buttons
        last_press = keyevents[-1].rtc
        print "correct (%dms)" % last_press
        flash(usbbox)
    else:
        print "user said:", " ".join([BUTTON_COLORS[event.key_code] for event in keyevents])
        print "wrong"
        flash(usbbox, rate=0.25, count=3)

    return correct


usbbox = USBBox()

print "Simon Says"
print "consists of several rounds of sequences being shown:"
print "1) LEDs will flash on box"
print "2) a sequence of LEDs will be shown"
print "3) after the sequence finishes the LEDs will flash again"
print "4) enter in the sequence previously shown (press the buttons that match the LEDs)"
print "5) if you get it right the LEDs will flash once and it'll repeat the cycle (with one more item to remember)"
print "6) if you get it wrong the LEDs will flash three times and you'll be asked if you want to play a new game"

# use logset so that 1 turns LED on and 0 turn LED off
usbbox.leds.logic = 0xFF
# and turn off the LEDs
usbbox.leds.state = 0x00
# ensure loop back isn't set