public
Created

  • Download Gist
led_matrix.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include <SPI.h>
 
#define CHIP_SELECT_PIN 10
 
void setup() {
// Setup SPI communication for the MAX7221.
pinMode(CHIP_SELECT_PIN, OUTPUT);
SPI.begin();
 
// Test for 1 second.
send(0x0F, 0x01);
delay(1000);
send(0x0F, 0x00);
 
// Turn off decoding.
send(0x09, 0x00);
 
// Set scan limiter to display all registers.
send(0x0B, 0x07);
 
// Set display intensity (0-F).
send(0x0A, 0x04);
 
// Turn on display.
send(0x0C, 0x01);
 
// Clear all the display registers.
send(0x01, 0x00);
send(0x02, 0x00);
send(0x03, 0x00);
send(0x04, 0x00);
send(0x05, 0x00);
send(0x06, 0x00);
send(0x07, 0x00);
send(0x08, 0x00);
}
 
void loop() {
send(0x01, random(256));
send(0x02, random(256));
send(0x03, random(256));
send(0x04, random(256));
send(0x05, random(256));
send(0x06, random(256));
send(0x07, random(256));
send(0x08, random(256));
delay(1000);
}
 
void send(byte address, byte value) {
digitalWrite(CHIP_SELECT_PIN, LOW);
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(CHIP_SELECT_PIN, HIGH);
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.