mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-10 09:53:42 +00:00
Driver for BBC micro:bit on-board LED matrix (#48)
This commit is contained in:
committed by
Ron Evans
parent
a9e5c8f710
commit
d22cf7a3e1
@@ -0,0 +1,59 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"image/color"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/tinygo-org/drivers/microbitmatrix"
|
||||
)
|
||||
|
||||
var display microbitmatrix.Device
|
||||
|
||||
func main() {
|
||||
display = microbitmatrix.New()
|
||||
display.Configure(microbitmatrix.Config{})
|
||||
|
||||
display.ClearDisplay()
|
||||
|
||||
x := int16(1)
|
||||
y := int16(2)
|
||||
deltaX := int16(1)
|
||||
deltaY := int16(1)
|
||||
then := time.Now()
|
||||
c := color.RGBA{255, 255, 255, 255}
|
||||
|
||||
for {
|
||||
if time.Since(then).Nanoseconds() > 80000000 {
|
||||
then = time.Now()
|
||||
|
||||
pixel := display.GetPixel(x, y)
|
||||
if pixel {
|
||||
display.ClearDisplay()
|
||||
x = 1 + int16(rand.Int31n(3))
|
||||
y = 1 + int16(rand.Int31n(3))
|
||||
deltaX = 1
|
||||
deltaY = 1
|
||||
if rand.Int31n(2) == 0 {
|
||||
deltaX = -1
|
||||
}
|
||||
if rand.Int31n(2) == 0 {
|
||||
deltaY = -1
|
||||
}
|
||||
}
|
||||
display.SetPixel(x, y, c)
|
||||
|
||||
x += deltaX
|
||||
y += deltaY
|
||||
|
||||
if x == 0 || x == 4 {
|
||||
deltaX = -deltaX
|
||||
}
|
||||
|
||||
if y == 0 || y == 4 {
|
||||
deltaY = -deltaY
|
||||
}
|
||||
}
|
||||
display.Display()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user