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
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
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);
}
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);
}