예제 #1
0
def roll(count, sides):
    for i in range(15):
        roll_value = sum([randint(1, sides) for _ in range(count + 1)])
        roll_label.text = str(roll_value)
        roll_label.x = 120 - (roll_label.bounding_box[2] // 2)
        duration = (i * 0.05) / 2
        clue.play_tone(2000, duration)
        time.sleep(duration)
예제 #2
0
def countdown(duration):
    duration = max(duration, 1)  # Check and set duration to at least 1 second
    duration /= 4  # Set duration to a quarter of itself
    clue_data[0].text = '3'  # Set countdown status
    clue_data.show()  # Display countdown status
    clue.play_tone(1046.5, duration)  # Play tone
    clue_data[0].text = '2'
    clue_data.show()
    clue.play_tone(1147.7, duration)
    clue_data[0].text = '1'
    clue_data.show()
    clue.play_tone(1568, (duration * 2))
    # Stop scanning whether or not we are connected.
    ble.stop_scan()

    try:
        if ibbq_connection and ibbq_connection.connected:
            clue.pixel.fill((0, 0, 50))
            ibbq_service = ibbq_connection[IBBQService]
            ibbq_service.init()
            while ibbq_connection.connected:

                if clue.button_a:  # hold a to swap between C and F
                    print("unit_mode swapped")
                    unit_mode = not unit_mode
                    clue.red_led = True
                    clue.play_tone(1200, 0.1)
                    clue.red_led = False
                    time.sleep(0.1)  # debounce

                temps = ibbq_service.temperatures
                batt = ibbq_service.battery_level
                if temps is not None:
                    probe_count = len(temps)  # check how many probes there are
                    for i in range(probe_count):
                        if temps[i] != 0 and temps[
                                i] < 1000:  # unplugged probes
                            if unit_mode:
                                clue.pixel.fill((50, 0, 0))
                                temp = temps[i]
                                my_labels[i].text = "{} C".format(temp)
                                clue.pixel.fill((0, 0, 0))
        if neopixel_values is not None:
            start = neopixel_values.start
            if start > NEOPIXEL_BUF_LENGTH:
                continue
            data = neopixel_values.data
            data_len = min(len(data), NEOPIXEL_BUF_LENGTH - start)
            neopixel_buf[start : start + data_len] = data[:data_len]
            if neopixel_values.write_now:
                neopixel_write.neopixel_write(neopixel_out, neopixel_buf)

        if now_msecs - temp_last_update >= temp_svc.measurement_period:
            temp_svc.temperature = clue.temperature
            temp_last_update = now_msecs

        tone = tone_svc.tone
        if tone is not None:
            freq, duration_msecs = tone
            if freq != 0:
                if duration_msecs != 0:
                    # Note that this blocks. Alternatively we could
                    # use now_msecs to time a tone in a non-blocking
                    # way, but then the other updates might make the
                    # tone interval less consistent.
                    clue.play_tone(freq, duration_msecs / 1000)
                else:
                    clue.stop_tone()
                    clue.start_tone(freq)
            else:
                clue.stop_tone()
        last_tone = tone
print("shake")
# wait for shake
while not clue.shake(shake_threshold=SHAKE_THRESHOLD):
    pass

# calibrate the mystic universe
x, y, z = clue.acceleration
random.seed(int(time.monotonic() + abs(x) + abs(y) + abs(z)))

# cast a reading
reading = random.randrange(64)
print("reading = ", reading, HEXAGRAMS[reading])

# play a melody
for note, duration in MELODY:
    clue.play_tone(note, duration)

# prompt to show
display.auto_refresh = False
hexname.text = "      GOT IT\n\nPRESS BUTTON\n       TO SEE"
hexname.anchored_position = (120, 120)
display.auto_refresh = True
while not clue.button_a and not clue.button_b:
    pass

# and then show it
display.auto_refresh = False
splash.append(hexagram)
show_hexagram(reading)
show_name(reading)
display.auto_refresh = True
예제 #6
0
    return int(sample_sum / samples)


# Instantiate and calibrate load cell inputs
print("*** Instantiate and calibrate load cells")
clue.pixel[0] = (16, 16, 0)  # Set status indicator to yellow
print("    enable NAU7802 digital and analog power: %5s" %
      (nau7802.enable(True)))

nau7802.gain = DEFAULT_GAIN  # Use default gain
nau7802.channel = 1
zero = zero_channel()  # Calibrate and get raw zero offset value
nau7802.channel = 2
zero = zero_channel()  # Calibrate and get raw zero offset value
clue.pixel[0] = (0, 16, 0)  # Set status indicator to green
clue.play_tone(1660, 0.15)
clue.play_tone(1440, 0.15)

print("GAIN:", DEFAULT_GAIN)
print("Place the calibration weight on the load cell")
print("To re-zero the load cells, remove all weights and press B")

### Main loop: Read load cells and display raw values
#     Monitor Zeroing button
while True:
    print("=====")
    nau7802.channel = 1
    value = read(SAMPLE_AVG)
    print(
        "CHAN_%1.0f RAW VALUE: %7.0f  Percent of full-scale at gain x%3.0f : %3.2f: "
        % (nau7802.channel, value, DEFAULT_GAIN,
예제 #7
0
from adafruit_midi.note_on import NoteOn

screen = clue.simple_text_display(text_scale=2, colors=(clue.GREEN,))

screen[0].color = clue.YELLOW
screen[1].color = clue.GREEN
screen[2].color = clue.SKY
screen[3].color = clue.BLUE
screen[4].color = clue.BLUE
screen[5].color = clue.BLUE
screen[0].text = "ORCA playing"
screen[1].text = "Popcorn on Clue"
screen[2].text = "Thanks"
screen[3].text = "@ Hundredrabbits"
screen[4].text = "@ Adafruit"
screen[5].text = "@ Gershon Kingsley"
screen.show()

midi = adafruit_midi.MIDI(
    midi_in=usb_midi.ports[0],
    in_channel=(1),)
    
while True:
    msg_in = midi.receive()
    if isinstance(msg_in, NoteOn) != 0:    
        zahl = (440 / 32) * (2 ** ((msg_in.note - 9) / 12))
        clue.play_tone (zahl, 0.1)
        screen[6].text = int(zahl), "in Hz"
        screen[7].text = msg_in.note, "Midi Note"
        screen.show()