forked from tinygo-org/gobadge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
music.go
58 lines (49 loc) · 1.11 KB
/
music.go
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
58
package main
import (
"image/color"
"machine"
"time"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freesans"
)
func Music() {
white := color.RGBA{255, 255, 255, 255}
display.FillScreen(white)
tinyfont.WriteLine(&display, &freesans.Bold24pt7b, 0, 50, "MUSIC", color.RGBA{0, 100, 250, 255})
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, 20, 100, "Press any key", color.RGBA{200, 0, 0, 255})
for {
pressed, _ := buttons.Read8Input()
if pressed&machine.BUTTON_SELECT_MASK > 0 {
break
}
if pressed&machine.BUTTON_START_MASK > 0 {
tone(5274)
}
if pressed&machine.BUTTON_A_MASK > 0 {
tone(1046)
}
if pressed&machine.BUTTON_B_MASK > 0 {
tone(1975)
}
if pressed&machine.BUTTON_LEFT_MASK > 0 {
tone(329)
}
if pressed&machine.BUTTON_RIGHT_MASK > 0 {
tone(739)
}
if pressed&machine.BUTTON_UP_MASK > 0 {
tone(369)
}
if pressed&machine.BUTTON_DOWN_MASK > 0 {
tone(523)
}
}
}
func tone(tone int) {
for i := 0; i < 10; i++ {
bzrPin.High()
time.Sleep(time.Duration(tone) * time.Microsecond)
bzrPin.Low()
time.Sleep(time.Duration(tone) * time.Microsecond)
}
}