Esempio n. 1
0
def main():
    drumhat.all_off()

    for sample in samples:
        sample.start()

    drumhat.on_hit(drumhat.PADS, handle_hit)

    while True:
        for channel, sample in enumerate(samples):
            if not sample.sync and not sample.busy():
                drumhat.led_off(drumhat.NUMMAP[channel])

        time.sleep(1.0 / 30)
Esempio n. 2
0
    print(Id)
    from inventary import albums
    try:
        album = albums[Id]
        print(album)
        return album
    except KeyError:
        print("Oops! Id not known")
        return -1
    

def update_led(pad, status):
    print("Turn LED on Pad %d to %r") %(pad, status)
    if status == True:
        drumhat.led_on(pad)
    else:
        drumhat.led_off(pad)


drumhat.on_hit(drumhat.PADS, hit_handler)

try:
    drumhat.auto_leds = False
    drumhat.all_off()
    pads = drumhat.PADS
    while True:
       time.sleep(1)

except KeyboardInterrupt:
    exit()
Esempio n. 3
0
time.sleep(2)

#try/except语句用来检测try语句块中的错误,
#从而让except语句捕获异常信息并处理。
#小车循环前进1s,后退1s,左转2s,右转2s,原地左转3s
#原地右转3s,停止1s。

userin = 0
#userin = input("Press a command to use the car. Type q to leave.")

if userin != quit:
    motor_init()

while userin != "quit":
    try:
        drumhat.on_hit(drumhat.PADS, handle_hit)
        drumhat.on_release(drumhat.PADS, handle_release)
        #hile True:
        #    run(1)
        #fo
        #back(1)
        #left(2)
        #right(2)
        #spin_left(3)
        #spin_right(3)
        #brake(1)
    except KeyboardInterrupt:
        pass
    #userin = input("Press a command to use the car. Type q to leave.")

pwm_ENA.stop()
Esempio n. 4
0
6 = Hat,     8 = Clap,   3 = Cowbell
      5 = Snare,   4 = Base

Press CTRL+C to exit!
""")

BANK = os.path.join(os.path.dirname(__file__), DRUM_FOLDER)

pygame.mixer.init(44100, -16, 1, 512)
pygame.mixer.set_num_channels(16)

files = glob.glob(os.path.join(BANK, "*.wav"))
files.sort()

samples = [pygame.mixer.Sound(f) for f in files]

def handle_hit(event):
    # event.channel is a zero based channel index for each pad
    # event.pad is the pad number from 1 to 8
    samples[event.channel].play(loops=0)
    print("You hit pad {}, playing: {}".format(event.pad,files[event.channel]))

def handle_release():
    pass

drumhat.on_hit(drumhat.PADS, handle_hit)
drumhat.on_release(drumhat.PADS, handle_release)
 
while True:
    time.sleep(1)
Esempio n. 5
0
    def __init__(self, sound_index):
        super(Drums, self).__init__(sound_index)

        drumhat.on_hit(drumhat.PADS, self.handle_hit)
        drumhat.on_release(drumhat.PADS, self.handle_release)
Esempio n. 6
0
import drumhat
import time

def hit_handler(event):
    print("Hit on pad: {}".format(event.pad))

def rel_handler(event):
    print("Release on pad: {}".format(event.pad))

drumhat.on_hit(drumhat.PADS, hit_handler)
drumhat.on_release(drumhat.PADS, rel_handler)

try:
    drumhat.auto_leds = False
    pads = drumhat.PADS
    while True:
        drumhat.led_on(pads[-1])
        drumhat.led_off(pads[0])
        pads.insert(0,pads.pop())
        time.sleep(0.1)

except KeyboardInterrupt:
    exit()
Esempio n. 7
0
# triggers reset
def reset():
    print("reset")
    global hearts
    hearts = 3
    global speed
    speed = 0.5
    global counter
    counter = 0
    global score
    score = 1


# user input
# triggers reset
drumhat.on_hit(1, reset)
# triggers jump
drumhat.on_hit(8, hit_handler)


def tempo():
    global speed
    if counter == 7:
        speed = 0.925 * speed


def sky():
    for y in range(height):
        for x in range(width):
            unicorn.set_pixel(x, y, 50, 100, 255)