Example #1
0
def merry_christmas(pixels, slice=3):
    x = 0
    y = slice
    counter = 0
    len_pixel = int(len(cpx.pixels))
    while counter < len_pixel:
        cpx.pixels[x] = RED
        time.sleep(0.3)
        if x is not 9:
            pixels[x + 1] = CYAN
            time.sleep(0.3)
            pixels[x + 2] = GREEN
            time.sleep(0.3)
            x = y
            y = y + slice
        counter = counter + 1
    cpx.play_file("carol_of_the_bells_mono.wav")
    x = 0
    y = slice
    counter = 0
    while counter < len_pixel:
        cpx.pixels[x] = CYAN
        time.sleep(0.3)
        if x is not 9:
            cpx.pixels[x + 1] = GREEN
            time.sleep(0.3)
            cpx.pixels[x + 2] = RED
            time.sleep(0.3)
            x = y
            y = y + slice
        counter = counter + 1
    cpx.play_file("carol_of_the_bells_mono.wav")
    cpx.pixels.fill(WHITE)
    cpx.pixels.fill(BLACK)
Example #2
0
def start_sound(autoWrite, brightness, play_sound):
    pixels.brightness = high_light
    pixels.auto_write = autoWrite
    for number in range(30):
        if number <= 14:
            pixels[number] = (blue)
        elif number >= 15:
            pixels[number] = (red)
    pixels.show()
    if play_sound:
        cpx.play_file('protonpack_start.wav')
    else:
        sleep(1)
    pixels.fill((off))
    pixels.show()
    sleep(0.1)
    for _ in range(5):
        pixels.fill((blue))
        pixels.show()
        sleep(0.2)
        pixels.fill((off))
        pixels.show()
        sleep(0.1)
        pixels.fill((red))
        pixels.show()
        sleep(0.2)
        pixels.fill((off))
        pixels.show()
Example #3
0
 def growl(self):
     cpx.play_file("gator.wav")
     for t in range(5):
         self.setRing(self.color_growling)
         time.sleep(.05)
         self.setRing(self.color_mood)
         time.sleep(.05)
Example #4
0
def HedwigsTheme():
    # E(low) A C B A E(high) D B A C B G (low) Bflat E (low)
    cpx.play_tone(247, .2)  # low B
    cpx.play_tone(329, .2)  #E (low)
    cpx.play_tone(392, .1)  # G (low)
    cpx.play_tone(369, .1)  #F sharp (low)

    cpx.play_tone(329, .2)  #E (low)
    cpx.play_tone(493, .2)  # B
    cpx.play_tone(440, .4)  # A
    cpx.play_tone(369, .4)  #F sharp (low)

    cpx.play_tone(329, .2)  #E (low)
    cpx.play_tone(392, .1)  # G (low)
    cpx.play_tone(369, .1)  #F sharp (low)
    cpx.play_tone(293, .2)  #D (low)
    cpx.play_tone(349, .1)  #F (low)
    cpx.play_tone(247, .6)  #B (low)

    crickit.servo_2.angle = 20
    cpx.play_file("wingardium.wav")
    crickit.servo_2.angle = 15
    time.sleep(.1)
    crickit.servo_2.angle = 25
    time.sleep(.1)
    crickit.servo_2.angle = 15
    time.sleep(.1)
    crickit.servo_2.angle = 25
    time.sleep(.1)
    crickit.servo_2.angle = 15
    time.sleep(.1)
    crickit.servo_2.angle = 90
Example #5
0
def play(level):
    for i in range(2, level + 1):
        sequence = printGameColours(i)
        error = False
        hits = 0
        while (not error) and hits < i:
            if cpx.touch_A4 or cpx.touch_A5:
                printRB()
                if sequence[hits] == 0: hits += 1
                else: error = True
            elif cpx.touch_A6 or cpx.touch_A7:
                printRT()
                if sequence[hits] == 1: hits += 1
                else: error = True
            elif cpx.touch_A1:
                printLT()
                if sequence[hits] == 2: hits += 1
                else: error = True
            elif cpx.touch_A2 or cpx.touch_A3:
                printLB()
                if sequence[hits] == 3: hits += 1
                else: error = True

        if error:
            printError(sequence[hits])
            return

    cpx.play_file("win.wav")
Example #6
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)
Example #7
0
    def update(self):
        t_now = self.now()
        self.setRing(self.color_mood)
        if cpx.tapped:
            self.dlog("accept petting")
            self.onTap()

        if self.touch1.value:
            self.onTouch()

        if cpx.button_a:
            self.onButtonA()

        self.updateAccel()
        while self.a[2] < 0:
            self.dlog("upside down! sleepy...")
            self.fade(self.color_sleep1, self.color_sleep2, 0.5, 5)
            self.fade(self.color_sleep2, self.color_sleep1, 0.5, 5)
            cpx.play_file("snore.wav")
            self.updateAccel()
        if t_now - self.last_growl > 10.0:
            self.dlog("time to growl")
            if cpx.switch:
                self.growl()
            self.last_growl = self.now()
Example #8
0
def printLB():
    cpx.pixels[7] = (255, 0, 255)
    cpx.pixels[8] = (255, 0, 255)
    cpx.pixels[9] = (255, 0, 255)
    cpx.play_file("do.wav")
    time.sleep(0.6)
    cpx.pixels.fill((0, 0, 0))
    time.sleep(0.6)
Example #9
0
def printLT():
    cpx.pixels[5] = (255, 255, 0)
    cpx.pixels[6] = (255, 255, 0)
    cpx.pixels[7] = (255, 255, 0)
    cpx.play_file("re.wav")
    time.sleep(0.6)
    cpx.pixels.fill((0, 0, 0))
    time.sleep(0.6)
Example #10
0
def printRT():
    cpx.pixels[2] = (0, 255, 0)
    cpx.pixels[3] = (0, 255, 0)
    cpx.pixels[4] = (0, 255, 0)
    cpx.play_file("mi.wav")
    time.sleep(0.6)
    cpx.pixels.fill((0, 0, 0))
    time.sleep(0.6)
Example #11
0
def printRB():
    cpx.pixels[0] = (0, 255, 255)
    cpx.pixels[1] = (0, 255, 255)
    cpx.pixels[2] = (0, 255, 255)
    cpx.play_file("fa.wav")
    time.sleep(0.6)
    cpx.pixels.fill((0, 0, 0))
    time.sleep(0.6)
Example #12
0
    def read_solution(self, solution_hash8):

        solution_hash8 = self.byte_to_bitarr(solution_hash8, mode="bit")
        for bit in solution_hash8:
            try:
                cpx.play_file("sounds/" + str(bit) + ".wav")
            except OSError as e:
                print("Unable to read audio solution")
Example #13
0
def printError(error):
    fn = printFunctions[error]
    cpx.pixels.fill((255, 0, 0))
    time.sleep(0.2)
    cpx.pixels.fill((0, 0, 0))
    time.sleep(0.2)
    cpx.pixels.fill((255, 0, 0))
    time.sleep(0.2)
    cpx.pixels.fill((0, 0, 0))

    fn()
    cpx.play_file("lose.wav")
Example #14
0
def flash_red(pixels):
    """ Flashes the given pixels red. Also plays a sound. """

    clear_pixels()

    cpx.play_file("sound/bamp.wav")

    for _ in range(10):
        for i in pixels:
            cpx.pixels[i] = (50, 0, 0)
        sleep(.05)
        for i in pixels:
            cpx.pixels[i] = (0, 0, 0)
        sleep(.05)
Example #15
0
def roll_to_hit():
    init_pixels()
    total = roll(20)

    print("Total: %s" % total)

    display_roll_value(total)

    if total == 1:
        pixels.fill(RED)
        cpx.play_file("laugh.wav")

    if total == 20:
        cpx.play_file("fanfare.wav")
        rainbow_cycle(.001)
Example #16
0
def chooseLevel():
    level = 0
    cpx.play_file("level.wav")
    while True:
        cpx.pixels[level] = getLedColorByLevel(level)
        if cpx.button_a:
            cpx.pixels.fill((0, 0, 0))
            return level
        if cpx.button_b:
            if level < 9:
                level += 1
            else:
                level = 0
                cpx.pixels.fill((0, 0, 0))
        time.sleep(0.2)
Example #17
0
def rainbow(pixels):
    """ Cycles the given pixels through the rainbow and back. Also plays a sound. """

    cpx.play_file("sound/tada.wav")
    r, g, b = (30, 0, 0)

    for _ in range(75):
        for i in pixels:
            cpx.pixels[i] = (r, g, b)
    
        if r > 0 and b == 0:
            r -= 1
            g += 1
        if g > 0 and r == 0:
            g -= 1
            b += 1
        if b > 0 and g == 0 and r < 29:
            b -= 1
            r += 1
        sleep(.005)

    for _ in range(75):
        for i in pixels:
            cpx.pixels[i] = (r, g, b)

        if r > 0 and g == 0:
            r -= 1
            b += 1
        if b > 0 and r == 0:
            b -= 1
            g += 1
        if g > 0 and b == 0:
            g -= 1
            r += 1
        sleep(.005)

    clear_pixels()
        cpx.red_led = False

        if cpx.button_a:
            cpx.pixels.fill(GREEN)
            time.sleep(.2)
            cpx.pixels.fill(BLACK)

        if cpx.button_b:
            for i in range(16):
                step = i
                # light a pixel
                cpx.pixels[step_pixel[i]] = step_col[step_note[i]]
                cpx.pixels[step_pixel[i - 1]] = BLACK

                # play a file
                cpx.play_file(audio_files[step_note[i]])

                # sleep a beat
                time.sleep(beat)
            cpx.pixels.fill(BLACK)

    # beat programming mode
    else:  # switch is slid to the right, record mode
        cpx.red_led = True
        if cpx.button_a:  # clear pixels, reset step to first step
            cpx.pixels.fill(RED)
            time.sleep(.2)
            cpx.pixels.fill(BLACK)
            cpx.pixels[9] = WHITE
            step = 0
            step_advance = 0
Example #19
0
# Press the buttons to play wav files.
# REQUIRED LOADING coin.wav and eep.wav onto your CIRCUITPY drive
from adafruit_circuitplayground.express import cpx

while True:
    if cpx.button_a:
        cpx.play_file("coin.wav")
    elif cpx.button_b:
        cpx.play_file("eep.wav")
Example #20
0

def Weiter():  # Methode Weiter
    zwischenspeicher = cpx.pixels[0]
    for i in range(0, 8):
        cpx.pixels[i] = cpx.pixels[i + 1]
    cpx.pixels[8] = zwischenspeicher
    zwischenspeicher = cpx.pixels[0]


Loading()
Setup()
zwischenspeicher = cpx.pixels[0]
zielfarbe = cpx.pixels[9]
if cpx.switch:
    cpx.play_file("tryme.wav")

while True:
    cpx.pixels[9] = (0, 0, 0)
    zwischenspeicher = cpx.pixels[0]
    Recolor()
    time.sleep(0.12)
    cpx.pixels[9] = zielfarbe
    cpx.pixels[0] = zwischenspeicher

    if cpx.button_a:
        Recolor()
        Weiter()
    if cpx.button_b:
        Weiter()
    time.sleep(0.7)
Example #21
0
def roll(max, times=1, each_roll=0, end_add=0):
    cpx.play_file('diceroll.wav')
    total = 0
    for index in range(0, times):
        total += random.randint(1, max) + each_roll
    return total
Example #22
0
# screencast, edited out video, cropped the sound, then exported the audio.
# I then downloaded Audacity and used this product to lower the sound
# quality to 22,050 kHz and 16 bit. If you search online you can find several
# good Audacity tutorials. You can likely also record sound from video
# playing on your phone or computer using iOS video capture or QuickTime for
# the Mac.

#   More detail on using sound files with CPX can be found at:
#   https://learn.adafruit.com/circuitpython-made-easy-on-circuit-playground-express/play-file
#   Info on this project is at:

import time
import touchio
from adafruit_circuitplayground.express import cpx

cpx.play_file("I_am_groot_1.wav")
soundNumber = 1
# Plugged into USB, higher # below is better.
# Battery = less power, so 200 workded well for me.
# 500 was what I had been using.
touch_threshold = 750
cpx.adjust_touch_threshold(touch_threshold)

while True:
    if cpx.touch_A1:
        print("Touched A1!")
        cpx.play_file("I_am_groot_" + str(soundNumber) + ".wav")
        if soundNumber < 4:
            soundNumber = soundNumber + 1
        else:
            soundNumber = 1
Example #23
0
         elif shake == 4:
             cpx.pixels[3] = (255, 255, 0)
         elif shake == 5:
             cpx.pixels[4] = (255, 0, 255)
         elif shake == 6:
             cpx.pixels[5] = (0, 255, 255)
         elif shake == 7:
             cpx.pixels[6] = (255, 128, 0)
         elif shake == 8:
             cpx.pixels[7] = (0, 255, 128)
         elif shake == 9:
             cpx.pixels[8] = (128, 0, 255)
         else:
             cpx.pixels[9] = (64, 128, 255)
     if shake >= 10:
         cpx.play_file("laugh.wav")
 else:
     # ネオピクセルの光は全部消えたかな?
     kazu = 0
     shake = 0
     cpx.pixels[0] = (0, 0, 0)
     cpx.pixels[1] = (0, 0, 0)
     cpx.pixels[2] = (0, 0, 0)
     cpx.pixels[3] = (0, 0, 0)
     cpx.pixels[4] = (0, 0, 0)
     cpx.pixels[5] = (0, 0, 0)
     cpx.pixels[6] = (0, 0, 0)
     cpx.pixels[7] = (0, 0, 0)
     cpx.pixels[8] = (0, 0, 0)
     cpx.pixels[8] = (0, 0, 0)
     print("OFF")
from adafruit_circuitplayground.express import cpx
import time

while True:
    x, y, z = cpx.acceleration
    sum_accel = abs(x) + abs(y) + abs(z)
    print((sum_accel, 2))
    if sum_accel < 2:
        cpx.play_file("yikes.wav")
    time.sleep(0.1)
Example #25
0
def wheel(pos):
    # Input a value 0 to 255 to get a color value.
    # The colours are a transition r - g - b - back to r.
    if (pos < 0) or (pos > 255):
        return (0, 0, 0)
    if pos < 85:
        return (int(255 - pos*3), int(pos*3), 0)
    elif pos < 170:
        pos -= 85
        return (0, int(255 - (pos*3)), int(pos*3))
    else:
        pos -= 170
    return (int(pos*3), 0, int(255 - pos*3))

cpx.play_file("Coin.wav")   # Play a coin sound on boot

# Set up the accelerometer to detect tapping
cpx.detect_taps = 1    # detect single tap only

# Our counter for all 10 pixels
pixeln = 0
# We can tell the switch changed
last_switch = cpx.switch

while True:
    cpx.red_led = True                  # Turns the little LED next to USB on

    if cpx.tapped:     # Look for a single tap
        if random.randint(0, 1) == 0:   # Play one of two sounds...
            cpx.play_file("Coin.wav")
            cpx.pixels[p] = tuple([
                int(c * (10 - (pixel_number + p) % 10) / 10.0) for c in color
            ])
            cpx.pixels.show()

    # If the switch is to the left, it returns True!
    if cpx.switch:
        if now_led - start_led > 0.01:
            cpx.red_led = not cpx.red_led
            start_led = now_led
    else:
        cpx.red_led = False

    # Press the buttons to play sounds!
    if cpx.button_a:
        cpx.play_file("arnie.wav")
        board_id += random.randint(1, 2)
        board_id = board_id % 3
    elif cpx.button_b:
        cpx.play_file("smokin.wav")
        board_id += random.randint(1, 2)
        board_id = board_id % 3

    # Set TONE_PIANO to True above to enable a tone piano on the touch pads!
    if TONE_PIANO:
        if cpx.touch_A1:
            cpx.start_tone(262)
        elif cpx.touch_A2:
            cpx.start_tone(294)
        elif cpx.touch_A3:
            cpx.start_tone(330)
Example #27
0
    else:
        pos -= 170
    return (int(pos * 3), 0, int(255 - pos * 3))


def Temp_convert(temp, unit):
    unit = unit.lower()
    if unit == "c":
        temp = 9.0 / 5.0 * temp + 32
        return temp  #"%s degrees Fahrenheit"% temp
    if unit == "f":
        temp = (temp - 32) / 9.0 * 5.0
        return temp  #"%s degrees Celsius"% temp


cpx.play_file("Coin.wav")  # Play a coin sound on boot

# Set up the accelerometer to detect tapping
cpx.detect_taps = 1  # detect single tap only

# Our counter for all 10 pixels
pixeln = 0
# We can tell the switch changed
last_switch = cpx.switch

#led = digitalio.DigitalInOut(board.D13)
#led.direction = digitalio.Direction.OUTPUT

uart = busio.UART(board.TX, board.RX, baudrate=9600)

Test_lights = cpx.pixels
"""
Copyright 2019 CoderDojo Ofuna

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
"""
スイッチを変えて音を鳴らす。
"dip.wav"ファイルと"rise.wav"をCIRCUITPYフォルダにドラッグ&ドロップしましょう。
"""
from adafruit_circuitplayground.express import cpx

while True:
    if cpx.switch:
        cpx.play_file("dip.wav")
    else:
        cpx.play_file("rise.wav")
def prog_mode(index):
    cpx.play_file(audio_files[index])
    step_note[step] = index
    cpx.pixels[step_pixel[step]] = step_col[step_note[step]]
    print("playing file " + audio_files[index])
Example #30
0
def playno():
    counter = random.randint(1, 8)
    for i in range(1, 8):
        if counter == i:
            cpx.play_file("no-" + str(i) + ".wav")
Example #31
0
# create a PWMOut object on CPX Pin A1
pwm = pwmio.PWMOut(board.A1, frequency=50)
# Create a servo object cpx_servo
cpx_servo = servo.Servo(pwm)

hits = 0
max_hits = random.randint(3, 10)
cpx.detect_taps = 1  # Detect single taps
cpx_servo.angle = 0
cpx.pixels.fill((0, 0, 0))  # All NeoPixels off

while hits < max_hits:
    if cpx.tapped:
        print("Hit!")
        hits += 1
        cpx.pixels.fill((255, 255, 255))  # All White
        cpx.play_file("hit.wav")
        time.sleep(1.0)  # Wait time in seconds
        cpx.pixels.fill((0, 0, 0))  # All off
    time.sleep(0.1)

# Hits Reached, Payout!
print("Release!")
cpx.pixels.fill((0, 255, 0))  # All green
cpx.play_file("candy.wav")
cpx_servo.angle = 180
print("Press Reset or power cycle to reset device")
while True:
    pass  # Infinite loop, press Reset button to reset