Beispiel #1
0
def show_outcome(player, winner):
    # Turn them all off
    cpx.pixels.fill(0)

    # Set pixel color
    if winner:
        color = 0x00FF00
    else:
        color = 0xFF0000

    # Show which player won/lost
    for p in PLAYER_PIXELS[player]:
        cpx.pixels[p] = color

    # Play a little tune
    if winner:
        cpx.play_tone(800, 0.2)
        cpx.play_tone(900, 0.2)
        cpx.play_tone(1400, 0.2)
        cpx.play_tone(1100, 0.2)
    else:
        cpx.play_tone(200, 1)

    # Sit here forever
    while True:
        pass
Beispiel #2
0
def co2Sensor():
    i2c = busio.I2C(board.SCL, board.SDA, frequency=100000)
    sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c)
    print("SGP30 serial #", [hex(i) for i in sgp30.serial])

    sgp30.iaq_init()
    sgp30.set_iaq_baseline(0x8973, 0x8aae)

    elapsed_sec = 0
    #this loop is going to make all the lights go on before you can use the curcut playground
    for x in range(0, 9):
        cpx.pixels[x] = (50, 50, 0)
        time.sleep(2)
    # this is the thing that is allowing us to see our results
    while True:
        print('eCO2 = %d ppm \t TVOC = %d ppb' % (sgp30.eCO2, sgp30.TVOC))
        time.sleep(0.1)
        elapsed_sec += 1
        if elapsed_sec > 5:
            elapsed_sec = 0
            print("**** Baseline values: eCO2 = 0x%x, TVOC = 0x%x" %
                  (sgp30.baseline_eCO2, sgp30.baseline_TVOC))
        if sgp30.eCO2 >= CO2_THRESHOLD:
            cpx.pixels.fill((200, 0, 0))
            #playing a sound
            cpx.play_tone(FREQUENCY, 0.1)
        else:
            cpx.pixels.fill((20, 100, 0))
Beispiel #3
0
def sound_alarm():
    if alarm_wave:
        # play the pcm data
        cpx.play_file(ALARM_SOUND_FILE)
    else:
        # play a tone
        cpx.play_tone(800, 0.5)
def blue():
    cpx.pixels.fill((0,0,0))
    light_blue()
    cpx.pixels.show()
    if cpx.switch:
        cpx.play_tone(329.628,0.5)
    else:
        time.sleep(0.5)
def red():
    cpx.pixels.fill((0,0,0))
    light_red()
    cpx.pixels.show()
    if cpx.switch:
        cpx.play_tone(440.0,0.5)
    else:
        time.sleep(0.5)
def yellow():
    cpx.pixels.fill((0,0,0))
    light_yellow()
    cpx.pixels.show()
    if cpx.switch:
        cpx.play_tone(277.183,0.5)
    else:
        time.sleep(0.5)
def green():
    cpx.pixels.fill((0,0,0))
    light_green()
    cpx.pixels.show()
    if cpx.switch:
        cpx.play_tone(164.814,0.5)
    else:
        time.sleep(0.5)
Beispiel #8
0
def show_button(button, duration):
    cpx.pixels.fill(0)
    for p in button['pixels']:
        cpx.pixels[p] = button['color']
    if button['note'] == None:
        time.sleep(duration)
    else:
        cpx.play_tone(button['note'], duration)
    cpx.pixels.fill(0)
Beispiel #9
0
def game_won():
    for i in range(3):
        show_button(PLAYABLE_BUTTONS[4], 0.1)
        show_button(PLAYABLE_BUTTONS[2], 0.1)
        show_button(PLAYABLE_BUTTONS[3], 0.1)
        show_button(PLAYABLE_BUTTONS[1], 0.1)

    cpx.pixels.fill(0x00FF00)
    cpx.play_tone(WIN_TONE, 1.5)

    while True:
        pass
def game_lost(step):
    # Show button that should have been pressed
    cpx.pixels.fill(0)
    for p in SIMON_BUTTONS[sequence[step]]['pixels']:
        cpx.pixels[p] = SIMON_BUTTONS[sequence[step]]['color']

    # Play sad sound :(
    cpx.play_tone(FAILURE_TONE, 1.5)

    # And just sit here until reset
    while True:
        pass
Beispiel #11
0
def readDots():
    while True:
        dots = dotsToBinary()
        if (dots != 0) or (dots not in alphabet.dots_to_alphabet.keys()):
            returnDots = dots
            time.sleep(0.01)
        dots = dotsToBinary()
        if (dots != 0) and (dots == returnDots) and (
                dots in alphabet.dots_to_alphabet.keys()):
            cpx.play_tone(440, 0.1)
            while dotsToBinary() != 0:
                time.sleep(0.01)
            return dots
def indicate_button(button, duration):
    # Turn them all off
    cpx.pixels.fill(0)
    # Turn on the ones for the given button
    for p in button['pixels']:
        cpx.pixels[p] = button['color']
    # Play button tone
    if button['freq'] == None:
        time.sleep(duration)
    else:
        cpx.play_tone(button['freq'], duration)
    # Turn them all off again
    cpx.pixels.fill(0)
Beispiel #13
0
def flash_blink():
    for i in range(0, 10)
    cpx.play_tone(578, 1)
    cpx.pixels.fill((255, 0, 0))
    time.sleep(0.2)
    cpx.play_tone(578, 1)
    cpx.pixels.fill((0, 0, 0))
    time.sleep(0.2)

# Bright light
bright_light_level = 900

light_level = 0
while True:
    light_level = cpx.light
    print("Light Level:", cpx.light)
    if light_level > bright_light_level:
        print('JAR OPEN!!')
        flash_blink()
    else:
        print('Jar closed')
Beispiel #14
0
def sayHello():
    cpx.play_tone(160, .3)
    cpx.play_tone(220, .3)
    cpx.play_tone(260, .1)
    cpx.play_tone(320, .1)
    crickit.servo_1.angle = 160
    time.sleep(1)
    crickit.servo_1.angle = 170
    time.sleep(.1)
    crickit.servo_1.angle = 150
    time.sleep(.1)
    crickit.servo_1.angle = 170
    time.sleep(1)
    crickit.servo_1.angle = 90
Beispiel #15
0
from adafruit_circuitplayground.express import cpx

while True:
    if cpx.touch_A1:
        cpx.play_tone(262, 0.5)

    if cpx.touch_A2:
        cpx.play_tone(294, 0.5)

    if cpx.touch_A3:
        cpx.play_tone(330, 0.5)

    if cpx.touch_A4:
        cpx.play_tone(349, 0.5)
#
# Author: Carter Nelson
# MIT License (https://opensource.org/licenses/MIT)
import time
import math
from adafruit_circuitplayground.express import cpx

SLOUCH_ANGLE = 10.0
SLOUCH_TIME = 3
GRAVITY = 9.80665

# Initialize target angle to zero.
target_angle = 0

# Loop forever
while True:
    # Compute current angle
    current_angle = math.asin(-cpx.acceleration[2] / GRAVITY)
    current_angle = math.degrees(current_angle)

    # Set target angle on button press
    if cpx.button_a or cpx.button_b:
        target_angle = current_angle
        cpx.play_tone(900, 0.1)
        time.sleep(0.1)
        cpx.play_tone(900, 0.1)
        time.sleep(0.1)

    # Check if slouching
    if current_angle - target_angle > SLOUCH_ANGLE:
        cpx.play_tone(800, 0.5)
Beispiel #17
0
    cpx.pixels[9] = zielfarbe
    cpx.pixels[0] = zwischenspeicher

    if cpx.button_a:
        Recolor()
        Weiter()
    if cpx.button_b:
        Weiter()
    time.sleep(0.7)

    for i in range(0, 9):
        if (cpx.pixels[i] == zielfarbe):
            wincounter = wincounter + 1
    if (wincounter == 9):
        for i in range(0, 4):
            cpx.play_tone(225, 0.5)
            cpx.play_tone(275, 0.5)
            cpx.play_tone(250, 0.5)
            cpx.play_tone(300, 1)
        cpx.play_tone(300, 0.1)
        cpx.play_tone(250, 0.1)
        cpx.play_tone(275, 0.1)
        cpx.play_tone(225, 0.1)
        time.sleep(0.3)
        for i in range(0, 10):
            cpx.pixels[i] = OFF
        time.sleep(0.5)
        Loading()
        Setup()
        if cpx.switch:
            cpx.play_file("ashwga.wav")
Beispiel #18
0
pot_range = pot_high - pot_low

light_no = 0

while True:

    # figure out how long a beat is
    pot = analog_in.value
    # print((pot,))
    p = (pot-pot_low)/pot_range
    p = min(max(p,0),1)

    bpm = bpm_range[0] + p * (bpm_range[1]-bpm_range[0])
    print((bpm,))
    
    # work out when the next beat is - now + 1 beat.
    now = time.monotonic()
    next_beat = now + 60/bpm

    # thing that takes some time:
    # turn off the current light, bump, turn on next light, beep
    cpx.pixels[light_no] = (0, 0, 0)
    light_no =  (light_no + 1) % 4
    cpx.pixels[light_no] = (0, 255, 0)
    cpx.play_tone(320, .1)


    # wait for the beat
    sleep_time = next_beat - time.monotonic()
    time.sleep(sleep_time)
Beispiel #19
0
import time
from adafruit_circuitplayground.express import cpx

# Maximum temperature, in degrees C
MAX_TEMP = 24

# Minimum temperature, in degrees C
MIN_TEMP = 14

# NeoPixel Colors
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)

while True:
    # Take the temperature
    temp = cpx.temperature

    # Evaluate the temperature
    if temp > MAX_TEMP:
        cpx.play_tone(587, 5)
        cpx.pixels.fill(RED)
    elif temp < MIN_TEMP:
        cpx.play_tone(494, 5)
        cpx.pixels.fill(BLUE)
    else:
        cpx.pixels.fill(GREEN)

    # Let's wait a second before taking the temp again
    time.sleep(1)
Beispiel #20
0
    if x == 0 and y == -9:
        current_dial_position = 'C'
        cpx.pixels.fill((255, 70, 0))

    if x == -9 and y == 0:
        current_dial_position = 'D'
        cpx.pixels.fill((255, 255, 255))

    # press the right/B button to lock the servo
    if cpx.button_b:  # this is a more Pythonic way to check button status
        print('Locked/Reset')
        cpx.red_led = 1
        cpx.pixels.fill((50, 10, 10))
        lock_servo()
        cpx.play_tone(120, 0.4)
        cpx.pixels.fill((0, 0, 0))
        entered_combo = []  # clear this for next time around
        time.sleep(1)

    # press the left/A button to enter the current position as a combo entry
    if cpx.button_a:  # this means the button has been pressed
        # grab the current_dial_position value and add to the list
        entered_combo.append(current_dial_position)
        dial_msg = 'Dial Position: ' + \
                   str(entered_combo[(len(entered_combo) - 1)])
        print(dial_msg)
        cpx.play_tone(320, 0.3)  # beep
        time.sleep(1)  # slow down button checks

    if len(entered_combo) == 3:
Please support Adafruit and open source hardware by purchasing
products from Adafruit!

Written by Dave Astels for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.

All text above must be included in any redistribution.
"""

import time
from adafruit_circuitplayground.express import cpx

DOT_DURATION = 0.20
DASH_DURATION = 0.5

# You can adjust this to get the level of sensitivity you want.
cpx.adjust_touch_threshold(100)

while True:
    if cpx.touch_A4:
        cpx.play_tone(4000, DOT_DURATION)
        time.sleep(0.1)
        while cpx.touch_A4:
            pass
    elif cpx.touch_A3:
        cpx.play_tone(4000, DASH_DURATION)
        time.sleep(0.1)
        while cpx.touch_A3:
            pass

pulsein = pulseio.PulseIn(board.REMOTEIN, maxlen=120, idle_state=True)
decoder = adafruit_irremote.GenericDecode()

print("Start of wand detector")

while True:
    pulses = decoder.read_pulses(pulsein)
    if len(pulses) == 111:
        #print("Heard", len(pulses), "Pulses:", pulses)
        wand_id = getWandIDFromPulses(pulses)
        print(wand_id)
        if wand_id == '54d4b50':
            cpx.pixels.fill((RED))
            cpx.play_tone(262, 1)
        elif wand_id == '54eba60':
            cpx.pixels.fill((100,100,100))
            cpx.play_tone(294, 1)
        else:
            cpx.pixels.fill(GREEN)
        time.sleep(1) #Sleep for 1 second
    '''
    try:
        code = decoder.decode_bits(pulses)
        print("Decoded:", code)
    except adafruit_irremote.IRNECRepeatException:  # unusual short code!
        print("NEC repeat!")
    except adafruit_irremote.IRDecodeException as e:     # failed to decode
        print("Failed to decode: ", e.args)
    '''
Beispiel #23
0
def yellow():
    cpx.pixels[5] = YELLOW
    cpx.pixels[6] = YELLOW
    cpx.play_tone(1, 2)
    cpx.pixels[5] = BLACK
    cpx.pixels[6] = BLACK
Beispiel #24
0
from adafruit_circuitplayground.express import cpx

# Musicial scale to frequency mappings
# from https://ptolemy.berkeley.edu/eecs20/week8/scale.html
a = 440
b_flat = 466
b = 494
c = 523
c_sharp = 554
d = 587
d_sharp = 622
e = 659
f = 698
f_sharp = 740
g = 784
a_flat = 831
a = 880

# Try playing one of the tones above!
cpx.play_tone(a, 1)

# What happens if we increase the duration...
cpx.play_tone(c, 2)
# We can combine strings with the plus sign
prompt = "Hello " + name + " how are you?"
print(prompt)

# We can use the astrisks symbol with strings to multiply them
# e.x. "a" * 3 would result in the string "aaa"

# notes = 'a' * 2 + 'b' * 3 + "ccdg"  # this results in the string "aabbbccdg"

# =============================================== #
# ^^ For now just focus on the code above this ^^
# =============================================== #
import time
from adafruit_circuitplayground.express import cpx
import board

NOTE_TO_FREQUENCY = {
    "c": 261.63,
    "d": 293.66,
    "e": 329.63,
    "f": 349.23,
    "g": 392.00,
    "a": 440.00,
    "b": 493.88,
}
print("Playing notes: {}".format(notes))
for note in notes:
    if note in NOTE_TO_FREQUENCY.keys():
        cpx.play_tone(NOTE_TO_FREQUENCY[note], 0.15)
volSelect = 5

while True:
    cpx.pixels[select] = (255, 255, 255)
    cpx.volume = volume

    if (cpx.button_a) and select < 4:
        select += 1
        cpx.pixels[select - 1] = (0, 0, 0)
        time.sleep(0.2)

    if (cpx.button_b) and select > 0:
        select -= 1
        cpx.pixels[select + 1] = (0, 0, 0)
        time.sleep(0.2)

    if cpx.touch_A2 and volume < 1:
        volume += 0.25
        print(volume)
        time.sleep(0.2)
        cpx.pixels[volSelect] = (0, 255, 0)

    if cpx.touch_A3 and volume > 0:
        volume -= 0.25
        print(volume)
        time.sleep(0.2)
        cpx.pixels[volSelect] = (0, 255, 0)

    if (cpx.touch_A1) and select == 0:
        cpx.play_tone(15000, 2)
Beispiel #27
0
def guess(g):
    if g == pattern[0]:
        cpx.play_tone(300, 1)
Beispiel #28
0
while True:
    if cpx.touch_A3:
        if guessmode:
            guess(0)
    if cpx.touch_A4:
        if guessmode:
            guess(1)
    if cpx.touch_A5:
        if guessmode:
            guess(2)
    if cpx.touch_A6:
        if guessmode:
            guess(3)
    if cpx.touch_A7:
        if guessmode:
            guess(4)

    if cpx.button_a:
        cpx.play_tone(300, 1)
        cpx.play_tone(350, 1)
        cpx.play_tone(400, 1)
        cpx.play_tone(450, 1)
        cpx.play_tone(450, 1)
        cpx.play_tone(400, 1)
        cpx.play_tone(350, 1)
        cpx.play_tone(300, 1)
        cpx.play_tone(250, 1)
        showcolor()
        guessmode = True
from adafruit_circuitplayground.express import cpx

while True:
    if cpx.button_a:
        cpx.play_tone(260, 1)
    if cpx.button_b:
        cpx.play_tone(292, 1)
Beispiel #30
0
import time
from adafruit_circuitplayground.express import cpx

# Bright light
bright_light_level = 900

light_level = 0
while True:
    light_level = cpx.light
    print("Light Level:", cpx.light)
    if light_level > bright_light_level:
        print("JAR OPEN!")
        cpx.play_tone(587, 10)
    else:
        print("Jar closed")
    if cpx.shake():
        print("Who moved the cookie jar!")
        cpx.play_tone(523, 1)