2025年4月7日 星期一

傾聽作品:彩虹鳥和行動牛

 


MakeCode程式:


Python程式:

 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
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
    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)

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)

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

def on_forever():
    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(randint(1000, 10000))
basic.forever(on_forever)


沒有留言:

張貼留言