Skip to content

Instantly share code, notes, and snippets.

@rosswf
Last active April 30, 2023 19:51
Show Gist options
  • Save rosswf/fad0144ae52834cc51943af54280f58c to your computer and use it in GitHub Desktop.
Save rosswf/fad0144ae52834cc51943af54280f58c to your computer and use it in GitHub Desktop.
Arduino Clock using tinygo
package main
import (
"machine"
"time"
)
var (
hour uint8 = 6
min uint8 = 48
)
func main() {
hours := map[uint8]machine.Pin{
1: machine.D2,
2: machine.D3,
4: machine.D4,
8: machine.D5,
}
mins := map[uint8]machine.Pin{
1: machine.D7,
2: machine.D8,
4: machine.D9,
8: machine.D11,
}
for _, led := range hours {
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
}
for _, led := range mins {
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
}
for {
for k, v := range mins {
m := uint8(min / 5)
v.Set(m&k != 0)
}
for k, v := range hours {
v.Set(hour&k != 0)
}
time.Sleep(time.Minute)
min++
if min == 60 {
hour++
min = 0
}
if hour == 13 {
hour = 1
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment