diff --git a/LedMatrix.cpp b/LedMatrix.cpp index 560339e..125d914 100644 --- a/LedMatrix.cpp +++ b/LedMatrix.cpp @@ -9,6 +9,18 @@ LedMatrix::LedMatrix(byte numberOfDevices, byte slaveSelectPin) { myNumberOfDevices = numberOfDevices; mySlaveSelectPin = slaveSelectPin; cols = new byte[numberOfDevices * 8]; + rotatedCols = new byte[numberOfDevices * 8]; +} + +LedMatrix::LedMatrix(byte numberOfDevices, int8_t sck, int8_t miso, int8_t mosi, byte slaveSelectPin) { + myNumberOfDevices = numberOfDevices; + mySlaveSelectPin = slaveSelectPin; + cols = new byte[numberOfDevices * 8]; + rotatedCols = new byte[numberOfDevices * 8]; + customSpiPins = true; + _sck = sck; + _miso = miso; + _mosi = mosi; } /** @@ -17,8 +29,12 @@ LedMatrix::LedMatrix(byte numberOfDevices, byte slaveSelectPin) { */ void LedMatrix::init() { pinMode(mySlaveSelectPin, OUTPUT); - - SPI.begin (); + + if(customSpiPins){ + SPI.begin ( _sck, _miso, _mosi, mySlaveSelectPin); + } else { + SPI.begin (); + } SPI.setDataMode(SPI_MODE0); SPI.setClockDivider(SPI_CLOCK_DIV128); for(byte device = 0; device < myNumberOfDevices; device++) { @@ -33,7 +49,7 @@ void LedMatrix::init() { void LedMatrix::sendByte (const byte device, const byte reg, const byte data) { int offset=device; int maxbytes=myNumberOfDevices; - + for(int i=0;i +#include "LedMatrix.h" + + +#define NUMBER_OF_DEVICES 4 + +// Wiring that works with ESP32 +#define CS_PIN 15 +#define CLK_PIN 14 +#define MISO_PIN 2 //we do not use this pin just fill to match constructor +#define MOSI_PIN 12 + +LedMatrix ledMatrix = LedMatrix(NUMBER_OF_DEVICES, CLK_PIN, MISO_PIN, MOSI_PIN, CS_PIN); +int x = 0; + +void setup() { + ledMatrix.init(); + ledMatrix.setRotation(true); + + ledMatrix.setText("MAX7219 Animation Demo"); + ledMatrix.setNextText("Second text"); +} + +void loop() { + + ledMatrix.clear(); + ledMatrix.scrollTextLeft(); + ledMatrix.drawText(); + ledMatrix.commit(); + delay(50); + x=x+1; + if (x == 400) { + ledMatrix.setNextText("Third text"); + } +}