// MAX 7219 flame test
// MAX7219 bargraph display
// Select left or right insertion
// Lowest value LED blinks when the value is zero
// Select column height from one to eight LEDs
// Select row width from one to eight LEDs
//
// ⃝⃝⃝⃝⃝⃝⃝⃝ 0
// ⃝⃝⃝⃝⃝⃝⃝⃝ 1 Matrix LED identification
// ⃝⃝⃝⃝⃝⃝⃝⃝ 2
// ⃝⃝⃝⃝⃝⃝⃝⃝ 3 Rows
// ⃝⃝⃝⃝⃝⃝⃝⃝ 4
// ⃝⃝⃝⃝⃝⃝⃝⃝ 5
// ⃝⃝⃝⃝⃝⃝⃝⃝ 6
// ⃝⃝⃝⃝⃝⃝⃝⃝ 7
// 76543210
// Columns
#include <LedControl.h>
#define F_CPU 1600000L
#define CS_PIN 10
#define CLK_PIN 13
#define DIN_PIN 11
#define MAX_SEG 1
#include <LibPrintf.h>
uint8_t flameOut, flameBuild;
byte i, j;
// Set up the matrix control pins and maximum number of segments
LedControl matrixLEDDisplay = LedControl(DIN_PIN, CLK_PIN, CS_PIN, MAX_SEG); // MAX7219
void setup() {
Serial.begin(115200);
randomSeed(13);
matrixLEDDisplay.shutdown(0, false);
matrixLEDDisplay.setIntensity(0, 7);
matrixLEDDisplay.clearDisplay(0);
}
void loop() {
uint8_t matrix[8];
memset(matrix, 0x00, 8); // reset all the matrix bits
for (j = 0; j < 8; j++) {
flameBuild = 0x0;
long pixelOn;
// loop to turn on pixels
for (byte i = 0; i < j; i++) {
pixelOn = random(0, 8);
flameBuild = bitSet(flameBuild, pixelOn);
// if j=7 givee bottom row another chance
if (j == 7) {
pixelOn = random(0, 8);
flameBuild = bitSet(flameBuild, (byte) pixelOn);
}
//matrix[i] = flameBuild;
}
matrix[j] = flameBuild;
}
for (uint8_t i = 0; i < 8; i++) {
printf("%i\t%08b\n", i, matrix[i]); // print with formatting
}
printf("\n\n");
for(uint8_t i=0;i<8;i++){
matrixLEDDisplay.setRow(0,i,matrix[i]);
}
delay(170);
}