def game_of_thrones():
    # length of a beat
    beat = .1
    # Frequency of Pitch / # of beats to play pitch
    phrase1 = [
        (g3, 3), (c3, 3),
        (eb3, 0.5), (f3, 0.5), (g3, 2),
        (c3, 2), (eb3, .5), (f3, .5), (d3, 12)
    ]
    phrase2 = [
        (f3, 3), (bb3, 3),
        (eb3, .5), (d3, .5), (f3, 2), (bb3, 3),
        (eb3, .5), (d3, .5), (c3, 11)
    ]
    notes = []
    notes.extend(phrase1)
    notes.extend(phrase2)
    tmp = [(raise_octave(p), l) for p, l in notes]
    notes.extend(tmp)
    notes.append((25000, 12))

    for n in notes:
        if not cpx.switch and not cpx.button_a:
            break
        cpx.start_tone(n[0])
        time.sleep(beat * n[1])
        cpx.stop_tone()
Esempio n. 2
0
def play_song(song_number):
    # Preloaded with...
    # 1: Jingle bells
    # 2: Let It Snow
    # 3: Linus & Lucy

    # Choose to play a single song
    if song_number == 1:
        # Choose to play Jingle Bells
        song = jingle_bells
    # pylint: disable=consider-using-enumerate

    elif song_number == 2:
        # Choose to play Let it Snow
        song = let_it_snow

    elif song_number == 3:
        # Choose to play Linus & Lucy
        song = linus_and_lucy

    # Play each tone in the chosen song!
    for n in range(len(song)):
        # Break song playback if user interrupts with new shake
        if rolling == False:
            cpx.start_tone(song[n][0])
            time.sleep(song[n][1])
            cpx.stop_tone()
        else:
            break
 def change_tone_if_needed(self):
     """Find the frequency for the current arpeggio and tilt, and restart the tone if changed"""
     arpeggio_index = 0 if cpx.switch else 1
     freq = self.freq_maker.freq(TiltingArpeggios.tilt(), arpeggio_index)
     if freq != self.last_freq:
         self.last_freq = freq
         cpx.stop_tone()
         cpx.start_tone(freq)
def play_error():
    for led in [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]:
        cpx.pixels[led] = (255, 0, 0)
        
    cpx.start_tone(160)
    time.sleep(1)
    cpx.stop_tone()
    
    for led in [0, 1, 2, 3, 4, 5, 6, 7, 8 ,9]:
        cpx.pixels[led] = (0, 0, 0)
def play_song(song_number):
    # 1: Jingle bells
    # 2: Let It Snow

    # set up time signature
    whole_note = 1.5  # adjust this to change tempo of everything
    # these notes are fractions of the whole note
    half_note = whole_note / 2
    quarter_note = whole_note / 4
    dotted_quarter_note = quarter_note * 1.5
    eighth_note = whole_note / 8

    # set up note values
    A3 = 220
    Bb3 = 233
    B3 = 247
    C4 = 262
    Db4 = 277
    D4 = 294
    Eb4 = 311
    E4 = 330
    F4 = 349
    Gb4 = 370
    G4 = 392
    Ab4 = 415
    A4 = 440
    Bb4 = 466
    B4 = 494

    if song_number == 1:
        # jingle bells
        jingle_bells_song = [[E4, quarter_note], [E4, quarter_note],
                             [E4, half_note], [E4, quarter_note],
                             [E4, quarter_note], [E4, half_note],
                             [E4, quarter_note], [G4, quarter_note],
                             [C4, dotted_quarter_note], [D4, eighth_note],
                             [E4, whole_note]]

        for n in range(len(jingle_bells_song)):
            cpx.start_tone(jingle_bells_song[n][0])
            time.sleep(jingle_bells_song[n][1])
            cpx.stop_tone()

    if song_number == 2:
        # Let It Snow
        let_it_snow_song = [[B4, dotted_quarter_note], [A4, eighth_note],
                            [G4, quarter_note], [G4, dotted_quarter_note],
                            [F4, eighth_note], [E4, quarter_note],
                            [E4, dotted_quarter_note], [D4, eighth_note],
                            [C4, whole_note]]

        for n in range(len(let_it_snow_song)):
            cpx.start_tone(let_it_snow_song[n][0])
            time.sleep(let_it_snow_song[n][1])
            cpx.stop_tone()
Esempio n. 6
0
def simpleCircle(wait, R, G, B):  # timing, color values per channel
    baseFreq = int(20 + (G * 0.3))  # tone value derived from rotation

    for i in range(10):
        pixels[i] = ((0, 0, 0))
        cpx.start_tone(baseFreq + i)  # increasing pitch sweep
        time.sleep(wait)

    for i in range(10):
        pixels[i] = ((R, G, B))
        time.sleep(wait)
def simple_circle(wait, red, green, blue):
    """timing, color values per channel"""
    baseFreq = int(20 + (green * 0.3))  # tone value derived from rotation

    for i in range(10):
        cpx.pixels[i] = ((0, 0, 0))
        cpx.start_tone(baseFreq + i)  # increasing pitch sweep
        time.sleep(wait)

    for i in range(10):
        cpx.pixels[i] = ((red, green, blue))
        time.sleep(wait)
def lose_round():
    for i in range(10):
        cpx.stop_tone()
        if cpx.switch:
            cpx.start_tone( [220.0,190.0][i%2] )
        cpx.pixels.fill((32,0,0))
        for j in range(0,10,2):
            cpx.pixels[j] = (255,0,0)
        cpx.pixels.show()
        cpx.pixels.fill((32,0,0))
        for j in range(1,10,2):
            cpx.pixels[j] = (255,0,0)
        cpx.pixels.show()
    cpx.pixels.fill(0)
    cpx.pixels.show()
    cpx.stop_tone()
    time.sleep(0.25)
def light_region(region, duration=1):
    # turn the LEDs for the selected region on
    for led in REGION_LEDS[region]:
        cpx.pixels[led] = REGION_COLOR[region]

    # play a tone for the selected region
    cpx.start_tone(REGION_TONE[region])

    # wait the requested amount of time
    time.sleep(duration)

    # stop the tone
    cpx.stop_tone()

    # turn the LEDs for the selected region off
    for led in REGION_LEDS[region]:
        cpx.pixels[led] = (0, 0, 0)
Esempio n. 10
0
def win_round():
    for i in range(11):
        t = i/10.0
        cpx.stop_tone()
        if cpx.switch:
            cpx.start_tone( 220.0 * (1.0-t) + 440.0 * t )
        cpx.pixels.fill((0,32,0))
        for j in range(0,10,2):
            cpx.pixels[j] = (0,255,0)
        cpx.pixels.show()
        cpx.pixels.fill((0,32,0))
        for j in range(1,10,2):
            cpx.pixels[j] = (0,255,0)
        cpx.pixels.show()
    cpx.pixels.fill(0)
    cpx.pixels.show()
    cpx.stop_tone()
    time.sleep(0.25)
Esempio n. 11
0
def play_sounds():
    # A Minor Pentatonic
    tones = [587, 523, 440, 392, 330, 294, 262]
    for i in range(1, 8):
        cpx._touch(i)
    prev = 0
    touched = True

    while True:
        yield
        for i, touch in enumerate(cpx._touches[1:]):
            if touch.value:
                if not (i == prev and touched):
                    prev = i
                    cpx.stop_tone()
                cpx.start_tone(tones[i])
                touched = True
                break
        else:
            touched = False
def happy_birthday():
    notes = [(c4, .75), (c4, .25), (d4, 1), (c4, 1), (f4, 1),
             (e4, 2), (c4, .75), (c4, .25), (d4, 1), (c4, 1), (g4, 1), (f4, 2),
             (c4, .75), (c4, .25), (c5, 1), (a4, 1), (f4, 1), (e4, 1), (d4, 1),
             (bb4, .75), (bb4, .25), (a4, 1), (f4, 1), (g4, 1), (f4, 2),
             (25000, 8)]
    beat = 0.4
    for i, n in enumerate(notes):
        if not cpx.switch and not cpx.button_b:
            break
        begin = time.monotonic()
        cpx.start_tone(n[0])
        birthday_lights(clear=True)
        if n[1] >= 1:
            while time.monotonic() < begin + beat * n[1]:
                # alt_birthday_lights(n[1])
                wheel_lights()
        else:
            time.sleep(beat * n[1])
        cpx.stop_tone()
Esempio n. 13
0
from adafruit_circuitplayground.express import cpx
import time

BEEP_HIGH = 960
BEEP_LOW = 800

cpx.pixels.brightness = 0.10

cpx.start_tone(BEEP_HIGH)
for i in range(10):
    cpx.pixels[i] = 0xFF0000
    time.sleep(0.1)
cpx.stop_tone()

cpx.start_tone(BEEP_LOW)
for i in range(10):
    cpx.pixels[i] = 0x000000
    time.sleep(0.1)
cpx.stop_tone()
Esempio n. 14
0
            #digitalWrite(A5, LOW);  #disables the on/off button

        gTimer = 180

        cpx.red_led = True

        cpx.pixels.brightness = 0

        cpx.pixels[6] = (255, 255, 255)
        cpx.pixels[8] = (255, 0, 0)
        cpx.pixels[1] = (255, 255, 0)
        cpx.pixels[3] = (0, 0, 255)

        for i in range(5):
            cpx.stop_tone()
            cpx.start_tone(200 + (i * 25))
            cpx.pixels.brightness = (pixelMaxBrightness * (i / 5))
            time.sleep(.20)
        cpx.stop_tone()
        setup = 1

    if cpx.touch_A1 and whiteSwitchPriorState == 0:
        inputCode[count] = 1
        count += 1
        whiteSwitchPriorState = 1
        print("touched white A1, count is")
        print(count)
        print(inputCode)
        cpx.pixels[6] = (0, 0, 0)

    if cpx.touch_A3 and redSwitchPriorState == 0:
Esempio n. 15
0
from adafruit_circuitplayground.express import cpx

while True:
    if cpx.button_a:
        cpx.start_tone(262)
    elif cpx.button_b:
        cpx.start_tone(294)
    else:
        cpx.stop_tone()
    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)
        elif cpx.touch_A4:
            cpx.start_tone(349)
        elif cpx.touch_A5:
            cpx.start_tone(392)
        elif cpx.touch_A6:
            cpx.start_tone(440)
        elif cpx.touch_A7:
            cpx.start_tone(494)
        else:
            cpx.stop_tone()
Esempio n. 17
0
def 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)
    elif cpx.touch_A4:
        cpx.start_tone(349)
    elif cpx.touch_A5:
        cpx.start_tone(392)
    elif cpx.touch_A6:
        cpx.start_tone(440)
    elif cpx.touch_A7:
        cpx.start_tone(494)
    else:
        cpx.stop_tone()
def touch_demo(demo_count):
    while True:
        if cpx.touch_A1:
            cpx.start_tone(330)
            cpx.pixels[6] = ((255, 0, 0))
            print("Touched A1!")
        elif cpx.touch_A2:
            cpx.start_tone(394)
            cpx.pixels[8] = ((255, 0, 0))
            print("Touched A2!")
        elif cpx.touch_A3:
            cpx.start_tone(294)
            cpx.pixels[9] = ((255, 0, 0))
            print("Touched A3!")
        elif cpx.touch_A4:
            cpx.start_tone(262)
            cpx.pixels[0] = ((255, 0, 0))
            print("Touched A4!")
        elif cpx.touch_A5:
            cpx.start_tone(440)
            cpx.pixels[1] = ((255, 0, 0))
            print("Touched A5!")
        elif cpx.touch_A6:
            cpx.start_tone(494)
            cpx.pixels[8] = ((255, 0, 0))
            print("Touched A6!")
        elif cpx.touch_A7:
            cpx.start_tone(523)
            cpx.pixels[3] = ((255, 0, 0))
            print("Touched A7!")
        elif cpx.button_a or cpx.button_b:
            while cpx.button_a or cpx.button_b:  #debounce
                time.sleep(0.1)
            demo_count = demo_count + 1
            return demo_count
        else:
            cpx.stop_tone()
            cpx.pixels.fill((0, 0, 0))
Esempio n. 19
0
def play(tone):
    global last_tone
    if last_tone != tone or last_tone == 0:
        cpx.stop_tone()
        cpx.start_tone(tone)
        last_tone = tone
Esempio n. 20
0

def set_pixels_color(pixels, color):
    for i in range(len(pixels)):
        pixels[i] = color
    pixels.show()

def clearPixels(pixels):
    set_pixels_color(pixels, (0,0,0))
        

while True:
    
    if cpx.touch_A1:
        print('Touched C')
        cpx.start_tone(C4)
        set_pixels_color(pixels, (255,0,0))
    elif cpx.touch_A2:
        print('Touched D')
        cpx.start_tone(D4)
        set_pixels_color(pixels, (255, 153, 0))
    elif cpx.touch_A3:
        print('Touched E')
        cpx.start_tone(E4)
        set_pixels_color(pixels, (255, 255, 0))
    elif cpx.touch_A4:
        print('Touched F')
        cpx.start_tone(F4)
        set_pixels_color(pixels, (51, 204, 51))
    elif cpx.touch_A5:
        print('Touched G')
import time
import board
import random
from adafruit_circuitplayground.express import cpx

while True:
    if cpx.switch:
        for x in range(10):
            cpx.pixels[x] = (255, 0, 200)
    else:
        for x in range(10):
            cpx.pixels[x] = (0, 0, 0)
        #time.sleep(1)
    if cpx.button_b:
        #time.sleep(3)
        print("button")
        cpx.start_tone(590)
    elif cpx.button_a:
        print('other button')
        cpx.start_tone(2000)
        for x in range(10):
            cpx.pixels[x] = (random.randint(0, 255), random.randint(0, 255),
                             random.randint(0, 255))
            time.sleep(.05)
    else:
        cpx.stop_tone()
Esempio n. 22
0
from adafruit_circuitplayground.express import cpx
import time

while True:
    # this is pretty much the range of human hearing
    for tone in range(20, 20000, 100):
        cpx.start_tone(tone)
        print(tone)
        time.sleep(.1)
        cpx.stop_tone()
Esempio n. 23
0
from adafruit_circuitplayground.express import cpx

while True:
    if cpx.button_a:
        cpx.start_tone(262)
    elif cpx.button_b:
        cpx.start_tone(294)
    else:
        cpx.stop_tone()
Esempio n. 24
0
from time import sleep
from adafruit_circuitplayground.express import cpx

while True:
    arr = [cpx.touch_A1, cpx.touch_A2, cpx.touch_A3, cpx.touch_A4, cpx.touch_A5, cpx.touch_A6, cpx.touch_A7]
    touched = False
    for i, pad in enumerate(arr):
        if pad:
            print(i+1)
            cpx.start_tone(220*(i+1))
            touched = True
    if not touched:
        cpx.stop_tone()
    sleep(0.05)
Esempio n. 25
0
    # neither buttons pressed
    #if not cpx.button_a and not cpx.button_b:
    #    cpx.pixels.brightness = 0.3

    # Check the switch
    if cpx.switch:
        if last_switch != cpx.switch: # if it moved, print it out
            print("Switch moved left")
    else:
        if last_switch != cpx.switch:
            print("Switch moved right")
    last_switch = cpx.switch

    if TOUCH_PIANO:
        if cpx.touch_A4:              #  If we set to play tones
            cpx.start_tone(524)
        elif cpx.touch_A5:
            cpx.start_tone(588)
        elif cpx.touch_A6:
            cpx.start_tone(660)
        elif cpx.touch_A7:
            cpx.start_tone(698)
        elif cpx.touch_A1:
            cpx.start_tone(784)
        elif cpx.touch_A2:
            cpx.start_tone(880)
        elif cpx.touch_A3:
            cpx.start_tone(988)
        else:
            cpx.stop_tone()           # nothing touched? turn off the audio
# the easy way to do touch with a CPX is just to call cpx.touch_A1, cpx.touch_A2, etc.
# you can also use the board and touchio modules
from touchio import TouchIn
import board

pinArray = [
    TouchIn(board.A1),
    TouchIn(board.A2),
    TouchIn(board.A3),
    TouchIn(board.A4),
    TouchIn(board.A5),
    TouchIn(board.A6),
    TouchIn(board.A7)
]
# these are the NeoPixels closest to teach touch pin
pixArray = [6, 8, 9, 1, 2, 3, 4]

while True:
    noTouch = True
    for num, pin in enumerate(pinArray):
        if pin.value:
            # if a pin is touched, num will be the index in the pinArray
            print(num)
            cpx.start_tone(220 * num)
            noTouch = False  # a pin was touched
            cpx.pixels[pixArray[num]] = (100, 0, 0)
    if noTouch:
        # if no pin is touched, no sound and no light
        cpx.pixels.fill((0, 0, 0))
        cpx.stop_tone()
    sleep(.1)
Esempio n. 27
0
        # wait for use to take finger off button
        while cpx.button_b:
            pass

    # Check for rolling
    if cpx.shake() or cpx.tapped:
        roll_start_time = time.monotonic()
        new_roll = True
        rolling = True
        
    # Rolling momentum
    # Keep rolling for a period of time even after shaking stops
    if new_roll:
        if time.monotonic() - roll_start_time > 1:
            rolling = False
        
    # Display status on NeoPixels
    if rolling:
        # Compute a random number from 1 to 6
        roll_number = random.randrange(1, 6 + 1)
        # Make some noise and show the dice roll number
        cpx.start_tone(random.randrange(400, 2000))
        show_die(cpx.pixels, roll_number, dice_color)
        time.sleep(0.02)
        cpx.stop_tone()
    elif new_roll:
        # Show the dice roll number
        new_roll = False
        show_die(cpx.pixels, roll_number, dice_color)
        roll_total += roll_number
Esempio n. 28
0
    # neither buttons pressed
    if not cpx.button_a and not cpx.button_b:
        cpx.pixels.brightness = 0.3

    # Check the switch
    if cpx.switch:
        if last_switch != cpx.switch: # if it moved, print it out
            print("Switch moved left")
    else:
        if last_switch != cpx.switch:
            print("Switch moved right")
    last_switch = cpx.switch

    if TOUCH_PIANO:
        if cpx.touch_A4:              #  If we set to play tones
            cpx.start_tone(524)
        elif cpx.touch_A5:
            cpx.start_tone(588)
        elif cpx.touch_A6:
            cpx.start_tone(660)
        elif cpx.touch_A7:
            cpx.start_tone(698)
        elif cpx.touch_A1:
            cpx.start_tone(784)
        elif cpx.touch_A2:
            cpx.start_tone(880)
        elif cpx.touch_A3:
            cpx.start_tone(988)
        else:
            cpx.stop_tone()           # nothing touched? turn off the audio
Esempio n. 29
0
def play_song(song_number):
    # 1: Jingle bells
    # 2: Let It Snow

    whole_note = 1.5 
    half_note = whole_note / 2
    quarter_note = whole_note / 4
    dotted_quarter_note = quarter_note * 1.5
    eighth_note = whole_note / 8

    A3 = 220
    Bb3 = 233
    B3 = 247
    C4 = 262
    Db4 = 277
    D4 = 294
    Eb4 = 311
    E4 = 330
    F4 = 349
    Gb4 = 370
    G4 = 392
    Ab4 = 415
    A4 = 440
    Bb4 = 466
    B4 = 494

    if song_number == 1:
        # jingle bells
        jingle_bells_song = [
            [E4, quarter_note],
            [E4, quarter_note],
            [E4, half_note],
            [E4, quarter_note],
            [E4, quarter_note],
            [E4, half_note],
            [E4, quarter_note],
            [G4, quarter_note],
            [C4, dotted_quarter_note],
            [D4, eighth_note],
            [E4, whole_note],
        ]
        for n in range(len(jingle_bells_song)):
            cpx.start_tone(jingle_bells_song[n][0])
            time.sleep(jingle_bells_song[n][1])
            cpx.stop_tone()

    if song_number == 2:
        # Let It Snow
        let_it_snow_song = [
            [B4, dotted_quarter_note],
            [A4, eighth_note],
            [G4, quarter_note],
            [G4, dotted_quarter_note],
            [F4, eighth_note],
            [E4, quarter_note],
            [E4, dotted_quarter_note],
            [D4, eighth_note],
            [C4, whole_note],
        ]

        for n in range(len(let_it_snow_song)):
            cpx.start_tone(let_it_snow_song[n][0])
            time.sleep(let_it_snow_song[n][1])
            cpx.stop_tone()
def play_error():
    cpx.start_tone(160)
    time.sleep(1)
    cpx.stop_tone()
Esempio n. 31
0
from adafruit_circuitplayground.express import cpx
from time import sleep

while True:
    # calling touch_A1, touch_A2, etc. causes the CPX to check if it's touched
    # it will return True or False
    if cpx.touch_A1:
        cpx.start_tone(440)
        print("A1")
    # python uses elif as short for "else if"
    elif cpx.touch_A2:
        cpx.start_tone(880)
        print("A2")
    else:
        cpx.stop_tone()
Esempio n. 32
0
     time.sleep(0.5)
 if cpx.button_b and m - d == 3 and l - s == 1 and dd - t == 1:  #If interval between 1st and 3rd is three: minor 3rd
     #if interval between 6th and 7th is one: flat 6, if interval between 8th and 7th is one, raised 7th
     #This makes it harmonic minor, and from here you raise the 6th to be in melodic minor
     l = l + 1
     print("You are in " + keys[d] + " Melodic Minor")
     time.sleep(0.5)
 if cpx.button_b and m - d == 3 and l - s == 2 and dd - t == 1:  #interval of 3 = minor 3rd 6th-5th being 2 semitones = raised 6th
     #8th to 7th being one semitone = raised 7th - melodic minor.  Raise the 3rd to be in major again
     m = m + 1
     print("You are in " + keys[d] + " Major")
     time.sleep(0.5)
 if cpx.touch_A4:  #A4 is always the 1st scale degree of the key so you play do - whatever index in the keys array that is
     print('Touched ' + keys[d])
     cpx.pixels.fill((15, 0, 0))
     cpx.start_tone(notes[keys[d]])
 elif cpx.touch_A5:  #A5 is always the 2nd scale degree of the key so you play re - whatever index in the keys array that is
     print('Touched ' + keys[r])
     cpx.pixels.fill((15, 5, 0))
     cpx.start_tone(notes[keys[r]])
 elif cpx.touch_A6:  #A6 is always the 3rd scale degree of the key so you play mi - whatever index in the keys array that is
     print('Touched ' + keys[m])
     cpx.pixels.fill((15, 15, 0))
     cpx.start_tone(notes[keys[m]])
 elif cpx.touch_A7:  #A7 is always the 4th scale degree of the key so you play fa - whatever index in the keys array that is
     print('Touched ' + keys[f])
     cpx.pixels.fill((0, 15, 0))
     cpx.start_tone(notes[keys[f]])
 elif cpx.touch_A1:  #A1 is always the 5th scale degree of the key so you play so - whatever index in the keys array that is
     print('Touched ' + keys[s])
     cpx.pixels.fill((0, 15, 15))