Skip to content

Instantly share code, notes, and snippets.

@DazWilkin
Created March 17, 2019 19:48
Show Gist options
  • Save DazWilkin/7c6daa9c6048d8b5761831a7420f603c to your computer and use it in GitHub Desktop.
Save DazWilkin/7c6daa9c6048d8b5761831a7420f603c to your computer and use it in GitHub Desktop.
tinygo year counter
https://play.golang.org/p/jBSgaIlNK1R
package main
import (
"machine"
"time"
)
func enumerate() {
var x, y uint8
for y = 0; y < 5; y++ {
for x = 0; x < 5; x++ {
machine.SetLEDMatrix(x, y)
time.Sleep(time.Second)
}
}
}
func display(c uint32) {
machine.ClearLEDMatrix()
var x, y uint8
for y = 0; y < 5; y++ {
for x = 0; x < 5; x++ {
// If the number is odd, illuminate this LED
if c&1 == 1 {
machine.SetLEDMatrix(x, y)
}
// Halve the number
c = c>>1
}
}
}
func main() {
machine.InitLEDMatrix()
enumerate()
time.Sleep(time.Second * 5)
var c uint32
for {
// 25(5*5) LEDs: 2^25 = 33554432
// Curiously this ~== number of seconds in a year
// So, this should take about a year to complete
for c = 0; c < 33554432; c++ {
display(c)
time.Sleep(time.Second)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment