File tree Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Expand file tree Collapse file tree 2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "time"
5
+
6
+ "github.com/hybridgroup/gopherbot"
7
+ )
8
+
9
+ func main () {
10
+ speaker := gopherbot .Speaker ()
11
+
12
+ left := gopherbot .LeftButton ()
13
+ right := gopherbot .RightButton ()
14
+
15
+ for {
16
+ if right .Pushed () {
17
+ speaker .Bleep ()
18
+ }
19
+
20
+ if left .Pushed () {
21
+ speaker .Bloop ()
22
+ }
23
+
24
+ time .Sleep (200 * time .Millisecond )
25
+ }
26
+ }
Original file line number Diff line number Diff line change
1
+ package gopherbot
2
+
3
+ import (
4
+ "machine"
5
+
6
+ "tinygo.org/x/drivers/buzzer"
7
+ )
8
+
9
+ // SpeakerDevice is the Gopherbot speaker.
10
+ type SpeakerDevice struct {
11
+ buzzer.Device
12
+ }
13
+
14
+ // Speaker returns the SpeakerDevice.
15
+ func Speaker () * SpeakerDevice {
16
+ enable := machine .PA30
17
+ enable .Configure (machine.PinConfig {Mode : machine .PinOutput })
18
+ enable .Set (true )
19
+
20
+ speaker := machine .A0
21
+ speaker .Configure (machine.PinConfig {Mode : machine .PinOutput })
22
+
23
+ bzr := buzzer .New (speaker )
24
+ return & SpeakerDevice {bzr }
25
+ }
26
+
27
+ // Bleep makes a bleep sound using the speaker.
28
+ func (s * SpeakerDevice ) Bleep () {
29
+ // do bleep
30
+ s .Tone (buzzer .C3 , buzzer .Eighth )
31
+ }
32
+
33
+ // Bloop makes a bloop sound using the speaker.
34
+ func (s * SpeakerDevice ) Bloop () {
35
+ // do bloop
36
+ s .Tone (buzzer .C5 , buzzer .Quarter )
37
+ }
You can’t perform that action at this time.
0 commit comments