Skip to content

Instantly share code, notes, and snippets.

@insom insom/spi-matrix.ino
Created Jun 13, 2016

Embed
What would you like to do?
Arduino SPI / Interrupt driven matrix display
#include <TimerOne.h>
#include <SPI.h>
#define COLS 5
#define LE 10
volatile char buf[COLS] = {0x0};
void setup() {
SPI.begin();
pinMode(10, OUTPUT);
for(int i = 0; i < COLS; i++) {
pinMode(2 + i, OUTPUT);
}
Timer1.initialize(1000);
Timer1.attachInterrupt(writeRegister);
}
void loop() {
buf[random(0, COLS)] = random(255);
delay(10);
}
void writeRegister() {
for(int i = 0; i < COLS + 1; i++) { // intentional off by one
SPI.transfer(buf[i]);
digitalWrite(2 + ((i + (COLS-1)) % COLS), LOW);
digitalWrite(LE, HIGH);
digitalWrite(LE, LOW);
digitalWrite(2 + i, HIGH);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.