Created
December 16, 2022 07:50
-
-
Save nobonobo/cd3aa30f52f5ab88ebc8e2fef49b7667 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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