2025年4月8日 星期二

傾聽作品:拍掌牛擺頭外也能啟閉鳥叫聲

上一篇文章:彩虹鳥和行動牛



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def on_button_pressed_a():
    radio.send_string("action cow")
input.on_button_pressed(Button.A, on_button_pressed_a)

def on_button_pressed_b():
    radio.send_string("rainbow bird")
input.on_button_pressed(Button.B, on_button_pressed_b)

def on_sound_loud():
    global mode
    if listen == 1:
        mode = (mode + 1) % 2
        basic.show_icon(IconNames.HEART)
        servos.P1.set_angle(60)
        basic.pause(500)
        servos.P1.set_angle(120)
        basic.pause(500)
        servos.P1.set_angle(90)
        basic.show_icon(IconNames.ANGRY)
input.on_sound(DetectedSound.LOUD, on_sound_loud)

listen = 0
mode = 0
strip = neopixel.create(DigitalPin.P2, 4, NeoPixelMode.RGB)
strip.show_rainbow(1, 360)
strip.show()
servos.P1.set_angle(90)
mode = 0
radio.set_group(88)
basic.show_icon(IconNames.ANGRY)
listen = 1
mode = 0

def on_every_interval():
    if mode == 1:
        strip.rotate(1)
        strip.show()
loops.every_interval(500, on_every_interval)

def on_forever():
    global listen
    if mode == 1:
        listen = 0
        for index in range(randint(10, 200)):
            music.play_sound_effect(music.create_sound_effect(WaveShape.SAWTOOTH,
                    randint(1, 5000),
                    randint(1, 5000),
                    randint(0, 1024),
                    randint(0, 1024),
                    randint(40, 100),
                    SoundExpressionEffect.VIBRATO,
                    InterpolationCurve.CURVE),
                SoundExpressionPlayMode.UNTIL_DONE)
        basic.pause(600)
        listen = 1
        basic.pause(randint(1000, 10000))
basic.forever(on_forever)

沒有留言:

張貼留言