-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
music.go
50 lines (42 loc) · 923 Bytes
/
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
package main
import (
"image/color"
"time"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/freesans"
)
func Music() {
white := color.RGBA{255, 255, 255, 255}
display.FillScreen(white)
w32, _ := tinyfont.LineWidth(&freesans.Bold24pt7b, "MUSIC")
tinyfont.WriteLine(&display, &freesans.Bold24pt7b, (320-int16(w32))/2, 110, "MUSIC", color.RGBA{0, 100, 250, 255})
tinyfont.WriteLine(&display, &freesans.Bold12pt7b, (320-int16(w32))/2, 160, "Press any key", color.RGBA{200, 0, 0, 255})
for {
if !btnA.Get() {
tone(1046)
}
if !btnB.Get() {
break
}
if !btnLeft.Get() {
tone(329)
}
if !btnRight.Get() {
tone(739)
}
if !btnUp.Get() {
tone(369)
}
if !btnDown.Get() {
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)
}
}