Arduino to Maxim 7219

Thread Starter

allenpitts

Joined Feb 26, 2011
163
Hello AAC forum,
Built an display that uses an Arduino Uno to control five Maxim 7219 chips and 296 LEDs.
It uses a PIR sensor (motion detector) to turn the display on,


Experimenting with using a FOR loop to controls the LEDS.
The display in the clip above uses

Code:
//Sketch runs LEDs on 4 boards of 64: 256  
//plus 40 LEDs on fifth board, total 296 LEDs
//191114 6 pm add PIR from LEDControl_180523_128_LEDs_PIR
// Arduino feedback LED not working may need to led var to high
// does the unsusal pattern twice and turns off
#include "LedControl.h"
LedControl lc=LedControl(12,11,10,5);
unsigned long delaytime=500;
unsigned long delaytime2=100;
int led = 7;                // the pin that the LED output is attached to
int sensor = 2; // the pin that the sensor is attached to
int state = LOW; // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)
void setup() {
//PIR setup
pinMode(led, OUTPUT); // initalize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input
lc.shutdown(0,false);
lc.shutdown(1,false); //second board
lc.shutdown(2,false); //third board
lc.shutdown(3,false); //fourth board
lc.shutdown(4,false);//fifth board

/* Set the brightness to a medium values */
lc.setIntensity(0,1);
lc.setIntensity(1,1);
lc.setIntensity(2,1);
lc.setIntensity(3,1);
lc.setIntensity(4,1);

/* and clear the display */
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
lc.clearDisplay(4);
}
void loop() {
   val = digitalRead(sensor);   // read sensor value
  if (val == HIGH) {           // check if the sensor is HIGH
{
for (int row=0; row<8; row++)
{
for (int col=0; col<8; col++)
{
lc.setLed(0,col,row,true); // turns on 1st board
lc.setLed(1,col,row,true); // turns on 2nd board
lc.setLed(2,col,row,true); // turns on 3rd board
lc.setLed(3,col,row,true); // turns on 4th board
lc.setLed(4,col,row,true); // turns on 5th board
delay(delaytime2);
}
}
for (int row=0; row<8; row++)
{
for (int col=0; col<8; col++)
{
lc.setLed(0,col,row,true); // turns off 1st board
lc.setLed(1,col,row,true); // turns off 2nd board
lc.setLed(2,col,row,true); // turns off 3rd board
lc.setLed(3,col,row,true); // turns off 4th board
lc.setLed(4,col,row,true); // turns off 5th board
delay(delaytime2);
}
}
}
 if (state == LOW) {
state = HIGH; // update variable state to HIGH
}
  }    
  else {
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds

if (state == HIGH){
state = LOW; // update variable state to LOW
}
  }
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
lc.clearDisplay(4);
}
Was trying to further condense with sketch copied below
but the display does not turn off.
The clear display statements are at the end but the display
stays on. The idea of the PIR sensor was that it would come
on when approached. turn off and then be ready to cycle again.

The first code works as designed but the second does not.

Thanks.

Allen in Dallas
Code:
//Sketch runs LEDs on 4 boards of 64: 256 
//plus 40 LEDs on fifth board, total 296 LEDs
//191114 6 pm add PIR  from LEDControl_180523_128_LEDs_PIR
// Arduino feedback LED not working  may need to led var to high
// does the unusal pattern but does not turn off

#include "LedControl.h"

LedControl lc=LedControl(12,11,10,5);

unsigned long delaytime=500;
unsigned long delaytime2=1;

int led = 7;                // the pin that the LED output is attached to
int sensor = 2;              // the pin that the sensor is attached to
int state = LOW;             // by default, no motion detected
int val = 0;                 // variable to store the sensor status (value)

void setup() {

//PIR setup
  pinMode(led, OUTPUT);      // initalize LED as an output
  pinMode(sensor, INPUT);    // initialize sensor as an input 

lc.shutdown(0,false);
lc.shutdown(1,false); //second board
lc.shutdown(2,false); //third board
lc.shutdown(3,false); //fourth board
lc.shutdown(4,false);//fifth board


/* Set the brightness to a medium values */
lc.setIntensity(0,1);
lc.setIntensity(1,1);
lc.setIntensity(2,1);
lc.setIntensity(3,1);
lc.setIntensity(4,1);


/* and clear the display */
lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2);
lc.clearDisplay(3);
lc.clearDisplay(4);
}

void loop() {

   val = digitalRead(sensor);   // read sensor value
  if (val == HIGH) {           // check if the sensor is HIGH

{
for (int row=0; row<8; row++)
{
  for (int col=0; col<8; col++)
  {
      for (int brd=0; brd<6; brd++)
            {
    lc.setLed(brd,col,row,true); // turns on 1st board
   //lc.setLed(brd,col,row,true); // turns on 2nd board
   // lc.setLed(brd,col,row,true); // turns on 3rd board
  //  lc.setLed(brd,col,row,true); // turns on 4th board
   // lc.setLed(brd,col,row,true); // turns on 5th board
   //  delay(delaytime2);
            }
  }
}

for (int row=0; row<8; row++)
{
  for (int col=0; col<8; col++)
  {
    for (int brd=0; col<6; brd++)
         {
    lc.setLed(brd,col,row,true); // turns off 1st board
  //  lc.setLed(brd,col,row,true); // turns off 2nd board
 //  lc.setLed(brd,col,row,true); // turns off 3rd board
  //  lc.setLed(brd,col,row,true); // turns off 4th board
 //   lc.setLed(brd,col,row,true); // turns off 5th board   
  //  delay(delaytime2);
         }
   }
}

}

 if (state == LOW) {
            state = HIGH;       // update variable state to HIGH
    }
  }     

  else {
      digitalWrite(led, LOW); // turn LED OFF
      delay(200);             // delay 200 milliseconds
      
      if (state == HIGH){
       state = LOW;       // update variable state to LOW
   }
  }

lc.clearDisplay(0);
lc.clearDisplay(1);
lc.clearDisplay(2); 
lc.clearDisplay(3); 
lc.clearDisplay(4); 
}
 

Thread Starter

allenpitts

Joined Feb 26, 2011
163
Hello All About Circuits,

Didn't get much reply on this. So I talked to my buddy and he says this could be done with a three dimensional array.

Anybody have idea how this might be done?

Thanks.

Allen in Dallas
 

MrSoftware

Joined Oct 29, 2013
2,202
I think you didn't get a lot of replies because there is a lot of code to thumb through. My suggestion would be try to simplify your code, move a lot of code to functions so your main loop is just a few function calls. And/or add some Serial.println() when things are supposed to happen, and log the output from your console so you can review what happened and determine what is missing. For example, when your PIR triggers, when you set or clear a display, etc.. Look back at the log to see what isn't happening as expected.
 

ebeowulf17

Joined Aug 12, 2014
3,307
I see typos in both of the for loops that you've added. In the first one, you just need to change 6 to 5:
Code:
for (int brd=0; brd<6; brd++)
In the second one, you're also checking the wrong variable as a condition. "col<6" should be changed to "brd<5"
Code:
for (int brd=0; col<6; brd++)
Not sure if this is the root cause of your problems, but hopefully it gets you at least 1 step closer.
 

Thread Starter

allenpitts

Joined Feb 26, 2011
163
Hello ebeowolff and the ACC forum,

Nice catch. Fixed those typos and it works great.
The first pattern is the sketch doing

Code:
void loop() {
 
lc.setLed(0,0,0,true);
    delay(delaytime2);
lc.setLed(0,0,1,true);
    delay(delaytime2); 
lc.setLed(0,0,2,true);
The second pattern, where it comes on in a more
random pattern is the FOR statement.

Thanks.

Allen in Dallas
 
Top