Merry Christmas to all of you,
nevertheless I have a problem and need one hint.
With my Arduino R3 I'm driving an array of 14 leds, common cathode mounted.
MAX7219 should do the job, but the results are not sufficient.
In my sketch I habe two routines:
in Single() I have control of the chosen two leds, but only if I add a delay() in the program.
In Show() I see the 6th led = Display[0][5] bright, but all the other ones are flickering very dim.
How can I solve this problem? What am I doing wrong?
Here is my code:
/* test.ino an array with 14 leds
*/
#include <SPI.h>
#include <avr/pgmspace.h>
#include <stdbool.h>
//
const byte MAX7219_REG_NOOP = 0x0;
const byte MAX7219_REG_DIGIT0 = 0x1; //
const byte MAX7219_REG_DIGIT1 = 0x2; //
const byte MAX7219_REG_DIGIT2 = 0x3; //
const byte MAX7219_REG_DIGIT3 = 0x4; //
const byte MAX7219_REG_DIGIT4 = 0x5; //
const byte MAX7219_REG_DIGIT5 = 0x6; //
const byte MAX7219_REG_DIGIT6 = 0x7; //
const byte MAX7219_REG_DIGIT7 = 0x8; //
const byte MAX7219_REG_DIGIT8 = 0x9; //
const byte MAX7219_REG_DECODEMODE = 0x9; //
const byte MAX7219_REG_INTENSITY = 0xA;
const byte MAX7219_REG_SCANLIMIT = 0xB;
const byte MAX7219_REG_SHUTDOWN = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;
// values
uint8_t ME1, ME2, ME4, ME8, MZ1, MZ2, MZ4, SE1, // 128 ... 1
SE2, SE4, SE8, SZ1, SZ2, Sec_P; // 128 ... 4
byte Display[2][8] {
{ 0,64, 0, 32, 0, 16, 0, 4},
{128, 0, 32, 0, 8, 4, 0, 0}
};
bool ledState = LOW;
bool State;
uint32_t previousMillis_1, currentMillis_1;
const uint32_t Interval_1 = 400;
const byte ledPin = 19; //
void setup() { // =================== setup
Serial.begin(115200);
SPI.begin ();
sendByte (MAX7219_REG_SCANLIMIT, 2); // show 2 rows
sendByte (MAX7219_REG_DECODEMODE, 0); //
sendByte (MAX7219_REG_DISPLAYTEST, 0); // no display test
sendByte (MAX7219_REG_INTENSITY, 10); // range: 0 to 15
sendByte (MAX7219_REG_SHUTDOWN, 1); // 1 = KEIN shutdown mode
for (byte col = 0; col < 8; col++) // clear display
sendByte (col + 1, 0);
Serial.println(" ====================================== ");
Serial.println(" ======== test.ino ==================== ");
Serial.println(" ====================== 25.12.21 ===== ");
pinMode(ledPin, OUTPUT);
} // ====== setup
void sendByte (const byte reg, const byte data) {
digitalWrite (SS, LOW);
SPI.transfer (reg);
SPI.transfer (data);
digitalWrite (SS, HIGH);
} // end of sendByte
void Show() { // 14 LED === display
byte i, j;
for (i = 0; i < 2; i++) { // 2 rows
for (j = 0; j < 8; j++) // 8 columns
{
sendByte(i+1,Display[i][j]);
}
}
}
void Single() {
sendByte(1, Display[0][1]); delay(300);
sendByte(1, 0); delay(300);
sendByte(2, Display[1][5]); delay(300);
sendByte(2, 0); delay(300);
}
void blink() {
unsigned long currentMillis_1 = millis();
if (currentMillis_1 - previousMillis_1 >= Interval_1)
{ previousMillis_1 = currentMillis_1;
ledState == LOW ? ledState = HIGH : ledState = LOW;
digitalWrite(ledPin, ledState);
}
}
void loop() { // ================================ loop ##2
//Single();
Show();
blink();
Serial.print(" array :"); Serial.print(Display[0][0]);
Serial.print(" "); Serial.print(Display[0][1]);
Serial.print(" "); Serial.print(Display[0][2]);
Serial.print(" "); Serial.print(Display[0][3]);
Serial.print(" "); Serial.print(Display[0][4]);
Serial.print(" "); Serial.print(Display[0][5]);
Serial.print(" "); Serial.print(Display[0][6]);
Serial.print(" "); Serial.print(Display[0][7]);
Serial.print(" "); Serial.print(Display[1][0]);
Serial.print(" "); Serial.print(Display[1][1]);
Serial.print(" "); Serial.print(Display[1][2]);
Serial.print(" "); Serial.print(Display[1][3]);
Serial.print(" "); Serial.print(Display[1][4]);
Serial.print(" "); Serial.print(Display[1][5]);
Serial.println();
}
