Skip to content

Instantly share code, notes, and snippets.

@nobonobo
Created December 16, 2022 07:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobonobo/cd3aa30f52f5ab88ebc8e2fef49b7667 to your computer and use it in GitHub Desktop.
Save nobonobo/cd3aa30f52f5ab88ebc8e2fef49b7667 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"machine"
"machine/usb/midi"
"time"
)
// Try it easily by opening the following site in Chrome.
// https://www.onlinemusictools.com/kb/
func main() {
led := machine.LED
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
m := midi.New()
m.SetHandler(func(b []byte) {
led.Set(!led.Get())
fmt.Printf("% X\r\n", b)
})
chords := []struct {
name string
keys []midi.Note
}{
{name: "C ", keys: []midi.Note{midi.C4, midi.E4, midi.G4}},
{name: "G ", keys: []midi.Note{midi.G3, midi.B3, midi.D4}},
{name: "Am", keys: []midi.Note{midi.A3, midi.C4, midi.E4}},
{name: "F ", keys: []midi.Note{midi.F3, midi.A3, midi.C4}},
}
index := 0
current := false
for {
current = !current
if current {
for _, c := range chords[index].keys {
m.NoteOff(0, 0, c, 0x40)
}
index = (index + 1) % len(chords)
} else {
for _, c := range chords[index].keys {
m.NoteOn(0, 0, c, 0x40)
}
}
time.Sleep(500 * time.Millisecond)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment