Ejemplo n.º 1
0
def play(location):
    display.show(Image.ALL_CLOCKS, delay=50, loop=True, wait=False)

    number = random.randrange(1, 10000)
    sleep(random.randrange(10, 500))
    radio.send(str(number))

    sleep(3000)

    numbers = []
    while True:
        message = radio.receive()
        if not message:
            break
        numbers.append(int(message))

    if number < min(numbers):
        location = "UNKNOWN"

    radio.off()

    display.show(Image.ARROW_E)

    seconds = 0
    start_time = running_time()
    button_b.was_pressed()

    while seconds < 8 * 60:
        if accelerometer.was_gesture("shake"):
            minutes = seconds // 60
            display.scroll("{0}:{1:02d}".format(minutes, seconds - minutes * 60))
        if button_b.was_pressed():
            display.scroll(location.upper())

        sleep(10)
        seconds = (running_time() - start_time) // 1000

    animation = [Image.SKULL, Image()]
    display.show(animation, delay=500, loop=True, wait=False)

    while True:
        sleep(10000)
        display.off()
Ejemplo n.º 2
0
from microbit import pin0, pin1, pin2, pin3, pin4, pin6, pin7, pin8, pin9, pin12, display, sleep
import radio

# This board needs to communicate with the servos so that when the LDR is triggered
# the servo board can be told to put down that monster. Also it means if a scoreboard
# microbit is added then it can listen to this for score totals.
radio.config(channel=42)
radio.on()

# Disable the display so that we can use the pins reserved for the display.
display.off()

class Window():
    """
    Haunted house window controls. Comprised of a light dependent resistor,
    a servo (controlled by a separate board slotted into a Kitronik 16 servo
    controller board) and a transistor, which is used like a relay to toggle
    external power (6V battery) to pairs of LEDs.
    """
    def __init__(self, ldr_pin, led_pin, name, short_name):
        self.led = led_pin
        self.ldr = ldr_pin
        self.name = name
        self.led_state = False
        self.led.write_digital(1) # power the transistor on startup to turn off LEDs
        self.short_name = short_name

    def light(self):
        return self.ldr.read_analog()
    
    def hit_test(self):
Ejemplo n.º 3
0
def game_over(image):
    display.show(image)
    radio.off()
    while True:
        sleep(10000)
        display.off()
Ejemplo n.º 4
0
def shutdown():
    while True:
        sleep(10000)
        display.off()