Remove microbit matrix (#319)
* Remove matrix code from bbc:microbit, and move it to a driver
Этот коммит содержится в:
родитель
7e46c1766d
коммит
fb952a722a
2 изменённых файлов: 10 добавлений и 72 удалений
|
@ -1,4 +1,4 @@
|
|||
// blink program for the BBC micro:bit that uses the entire LED matrix
|
||||
// blink program for the BBC micro:bit
|
||||
package main
|
||||
|
||||
import (
|
||||
|
@ -6,14 +6,19 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
// The LED matrix in the micro:bit is a multiplexed display: https://en.wikipedia.org/wiki/Multiplexed_display
|
||||
// Driver for easier control: https://github.com/tinygo-org/drivers/tree/master/microbitmatrix
|
||||
func main() {
|
||||
machine.InitLEDMatrix()
|
||||
|
||||
ledrow := machine.GPIO{machine.LED_ROW_1}
|
||||
ledrow.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
||||
ledcol := machine.GPIO{machine.LED_COL_1}
|
||||
ledcol.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT})
|
||||
ledcol.Low()
|
||||
for {
|
||||
machine.ClearLEDMatrix()
|
||||
ledrow.Low()
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
|
||||
machine.SetEntireLEDMatrixOn()
|
||||
ledrow.High()
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,11 +2,6 @@
|
|||
|
||||
package machine
|
||||
|
||||
import (
|
||||
"device/nrf"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// The micro:bit does not have a 32kHz crystal on board.
|
||||
const HasLowFrequencyCrystal = false
|
||||
|
||||
|
@ -79,65 +74,3 @@ const (
|
|||
LED_ROW_2 = 14
|
||||
LED_ROW_3 = 15
|
||||
)
|
||||
|
||||
// matrixSettings has the legs of the LED grid in the form {row, column} for each LED position.
|
||||
var matrixSettings = [5][5][2]uint8{
|
||||
{{LED_ROW_1, LED_COL_1}, {LED_ROW_2, LED_COL_4}, {LED_ROW_1, LED_COL_2}, {LED_ROW_2, LED_COL_5}, {LED_ROW_1, LED_COL_3}},
|
||||
{{LED_ROW_3, LED_COL_4}, {LED_ROW_3, LED_COL_5}, {LED_ROW_3, LED_COL_6}, {LED_ROW_3, LED_COL_7}, {LED_ROW_3, LED_COL_8}},
|
||||
{{LED_ROW_2, LED_COL_2}, {LED_ROW_1, LED_COL_9}, {LED_ROW_2, LED_COL_3}, {LED_ROW_3, LED_COL_9}, {LED_ROW_2, LED_COL_1}},
|
||||
{{LED_ROW_1, LED_COL_8}, {LED_ROW_1, LED_COL_7}, {LED_ROW_1, LED_COL_6}, {LED_ROW_1, LED_COL_5}, {LED_ROW_1, LED_COL_4}},
|
||||
{{LED_ROW_3, LED_COL_3}, {LED_ROW_2, LED_COL_7}, {LED_ROW_3, LED_COL_1}, {LED_ROW_2, LED_COL_6}, {LED_ROW_3, LED_COL_2}}}
|
||||
|
||||
// InitLEDMatrix initializes the LED matrix, by setting all of the row/col pins to output
|
||||
// then calling ClearLEDMatrix.
|
||||
func InitLEDMatrix() {
|
||||
set := 0
|
||||
for i := LED_COL_1; i <= LED_ROW_3; i++ {
|
||||
set |= 1 << uint8(i)
|
||||
}
|
||||
nrf.GPIO.DIRSET = nrf.RegValue(set)
|
||||
ClearLEDMatrix()
|
||||
}
|
||||
|
||||
// ClearLEDMatrix clears the entire LED matrix.
|
||||
func ClearLEDMatrix() {
|
||||
set := 0
|
||||
for i := LED_COL_1; i <= LED_COL_9; i++ {
|
||||
set |= 1 << uint8(i)
|
||||
}
|
||||
nrf.GPIO.OUTSET = nrf.RegValue(set)
|
||||
nrf.GPIO.OUTCLR = (1 << LED_ROW_1) | (1 << LED_ROW_2) | (1 << LED_ROW_3)
|
||||
}
|
||||
|
||||
// SetLEDMatrix turns on a single LED on the LED matrix.
|
||||
// Currently limited to a single LED at a time, it will clear the matrix before setting it.
|
||||
func SetLEDMatrix(x, y uint8) error {
|
||||
if x > 4 || y > 4 {
|
||||
return errors.New("Invalid LED matrix row or column")
|
||||
}
|
||||
|
||||
// Clear matrix
|
||||
ClearLEDMatrix()
|
||||
|
||||
nrf.GPIO.OUTSET = (1 << matrixSettings[y][x][0])
|
||||
nrf.GPIO.OUTCLR = (1 << matrixSettings[y][x][1])
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// SetEntireLEDMatrixOn turns on all of the LEDs on the LED matrix.
|
||||
func SetEntireLEDMatrixOn() error {
|
||||
set := 0
|
||||
for i := LED_ROW_1; i <= LED_ROW_3; i++ {
|
||||
set |= 1 << uint8(i)
|
||||
}
|
||||
nrf.GPIO.OUTSET = nrf.RegValue(set)
|
||||
|
||||
set = 0
|
||||
for i := LED_COL_1; i <= LED_COL_9; i++ {
|
||||
set |= 1 << uint8(i)
|
||||
}
|
||||
nrf.GPIO.OUTCLR = nrf.RegValue(set)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Загрузка…
Создание таблицы
Сослаться в новой задаче