Allen Pitts
asked on
Programming Arduino to control a Max7219 using C
Hello Expert,
Programming a micro chip called an Arduino Uno. It uses C.
I have a program that works. It controls 64 LEDS with this code
//LEDControl_151207
#include "LedControl.h" // need the library
LedControl lc=LedControl(12,11,10,2); //
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 2 as we are only using 2 MAX7219
void setup()
{
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,8);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
lc.shutdown(1,false);// turn off power saving, enables display
lc.setIntensity(1,8);// sets brightness (0~15 possible values)
lc.clearDisplay(1);// clear screen
}
void loop() {
lc.setLed(0,0,0,true);
delay(200);
lc.setLed(0,0,1,true);
delay(200);
lc.setLed(0,0,2,true);
delay(200);
....
lc.setLed(0,7,5,true);
delay(200);
lc.setLed(0,7,6,true);
delay(200);
lc.setLed(0,7,7,true);
delay(200);
lc.setLed(0,0,0,false);
delay(200);
lc.setLed(0,0,1,false);
delay(200);
lc.setLed(0,0,2,false);
delay(200);
....
lc.setLed(0,7,5,false);
delay(200);
lc.setLed(0,7,6,false);
delay(200);
lc.setLed(0,7,7,false);
delay(200);
}
The ellipsis in the code represents a continuation of the pattern.
I had some code that was much more efficient that did the
same thing but was much more efficient. It started like
.....
void loop() {
index IndexChip
index indexCol
index indexRow
.....
But I have lost it and I can't remember how
to rebuild it. If I could just begin the pattern
I could write it again.
Any ideas?
Thanks.
Allen in Dallas
Programming a micro chip called an Arduino Uno. It uses C.
I have a program that works. It controls 64 LEDS with this code
//LEDControl_151207
#include "LedControl.h" // need the library
LedControl lc=LedControl(12,11,10,2);
// pin 12 is connected to the MAX7219 pin 1
// pin 11 is connected to the CLK pin 13
// pin 10 is connected to LOAD pin 12
// 2 as we are only using 2 MAX7219
void setup()
{
lc.shutdown(0,false);// turn off power saving, enables display
lc.setIntensity(0,8);// sets brightness (0~15 possible values)
lc.clearDisplay(0);// clear screen
lc.shutdown(1,false);// turn off power saving, enables display
lc.setIntensity(1,8);// sets brightness (0~15 possible values)
lc.clearDisplay(1);// clear screen
}
void loop() {
lc.setLed(0,0,0,true);
delay(200);
lc.setLed(0,0,1,true);
delay(200);
lc.setLed(0,0,2,true);
delay(200);
....
lc.setLed(0,7,5,true);
delay(200);
lc.setLed(0,7,6,true);
delay(200);
lc.setLed(0,7,7,true);
delay(200);
lc.setLed(0,0,0,false);
delay(200);
lc.setLed(0,0,1,false);
delay(200);
lc.setLed(0,0,2,false);
delay(200);
....
lc.setLed(0,7,5,false);
delay(200);
lc.setLed(0,7,6,false);
delay(200);
lc.setLed(0,7,7,false);
delay(200);
}
The ellipsis in the code represents a continuation of the pattern.
I had some code that was much more efficient that did the
same thing but was much more efficient. It started like
.....
void loop() {
index IndexChip
index indexCol
index indexRow
.....
But I have lost it and I can't remember how
to rebuild it. If I could just begin the pattern
I could write it again.
Any ideas?
Thanks.
Allen in Dallas
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
if the function only repeats the two statements
lc.setLed(chip, column, row, onoff);
delay(ms);
for a known number of iterations you could do like
Open in new window
if the members chip, column and row would be iterated from 0 to some constant and have same values for 'onoff' and 'delay', you would use nested loops as shown by Karrtik rather than a 'table'.
Sara