Skip to content

Instantly share code, notes, and snippets.

@youngkin
Created May 18, 2022 19:32
Show Gist options
  • Save youngkin/2811bd14b580024ea92950aee6c33b9a to your computer and use it in GitHub Desktop.
Save youngkin/2811bd14b580024ea92950aee6c33b9a to your computer and use it in GitHub Desktop.
// Initialize SPI on the SPI0 associated GPIO pins
if err := rpio.SpiBegin(rpio.Spi0); err != nil {
fmt.Println(err)
os.Exit(1)
}
csPin.Output()
rpio.SpiChipSelect(uint8(csPin)) // Select CE0 (csPin) as slave
initMax7219()
for {
select {
case <-stop:
break
default:
for i := 0; i < NUM_CHARS; i++ {
for j := 1; j < MATRIX_ROW+1; j++ {
// 'j' starts at 1 since it's also used to reference the MAX7219 display registers
// which start at offset 1.
writeMax7219(byte(j), disp1[i][j-1])
}
time.Sleep(500 * time.Millisecond)
}
break
}
}
// Reset the SPI0 pins back to INPUT mode
rpio.SpiEnd(rpio.Spi0)
// Release SPI resources (e.g., mapped memory)
rpio.Close()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment