First attempt at looping through (not full) matrix led strip...

I think the 'grouping' works as it is.. because if I modify DISPLAY_TEST to be 0x01 and all leds come on.

'but'.. I'll re-write as you suggested anyways to be sure. :slight_smile:

secondly.. what delays are you referring to?

the serial print()'s?

update:

this seems to give me some promising/working results..

however... at this point.. while I learned how to use SPI a little bit.. and pass the binary format of the led states per group of 8..etc..

I am still left with the original question that started this thread?

this is NOT a matrix CUBE..
this IS an LED strip/ladder (soldered in matrix wiring to individually control/address the leds)
I do NOT have 64 leds in my led strip.... I only have 60.. so I was looking for a way to control that? better than the original code posted here?

(eventually I will another MAX7221 and another strip of 60 leds.. to make a complete 'circle'. so I'll want to loop and do patterns..etc)..

is there an easy way to increment in binary? or is pre-making my patterns and storing them in an array the best approach?

example:

using the LedControl lib.. I can just set col/row and either tru or false..

easy to increment a var (number) and change either true or false to maybe 'ping/pong' up & down the led strip?

Im not sure how I would do that here? I guess two arrays?

Also.. is there any way to CLEAR the display? I start up.. my leds are on?..a quick clear setting? or do I ned to loop through each group/led to turn it off?

thanks

anyways.. here is my current code:

thanks

#include <SPI.h>  

//-----[this is SPI hardware wiring pinout only]-----//
/* 
 Arduino pin D13 is connected to the DataIn (MAX7221 pin:13)
 Arduino pin D11 is connected to the CLK (MAX7221 pin:1)
 Arduino pin D10 is connected to LOAD (MAX7221 pin:12)
 */

// define MAX72xx default register addresses
#define DECODE_MODE 0x09 // Code B Decode Digits 0-7: 0xFF / No-Decode Mode: 0x00
#define INTENSITY_ADDRESS 0x0A // 0x07 to start, half intensity. valid from 0x00 (min) to 0x0F (max)
#define SCANLIMIT_ADDRESS 0x0B // All 8 digits on = 0xFF?? FF? Datasheet says 0x07?
#define SHUTDOWN_ADDRESS 0x0C  // Normal operation = 0x01 / Shutdown = 0x00 (powers up in shutdown mode)
#define DISPLAYTEST_ADDRESS 0x0F // 0x01 = all lights on full, 0x00 = normal ops

//---[define register addresses ['register/digit x' represent 1 section/grouping of 8 leds]---//
#define register1 0x01 // digit 0
#define register2 0x02 // digit 1
#define register3 0x03 // digit 2
#define register4 0x04 // digit 3
#define register5 0x05 // digit 4
#define register6 0x06 // digit 5
#define register7 0x07 // digit 6
#define register8 0x08 // digit 7

//--[define the SS pin]--//
#define SS 10 //hardware slave select pin on Arduino Due.
//--[deifne custom val]--//
#define totalGroups 8
//--[deifne custom val]--//
#define totalLeds 60

// create array to hold the register addresses
//byte registerAddress[] = {0,1,2,3,4,5,6,7};
byte registerAddress[] = {register1, register2, register3, register4, register5, register6, register7, register8};

// initialize array with some data/pattern
//byte registerData[] = {B10000000,B01000000,B00100000,B00010000,B00001000,B00000100,B00000010,B00000001}; 

//stay on pattern/array
byte registerData[] = {B10000000,B11000000,B11100000,B11110000,B11111000,B11111100,B11111110,B11111111}; 

void setup() {
  Serial.begin(9600);
  Serial.println("--SET UP CHIP--");
  //define 'SS' pin as output (needed for SPI....even if other devices use other pins as their SS/CS pins...correct?
  pinMode (SS, OUTPUT);
  // start the SPI library
  SPI.begin(); 

  //set MAX7221 defaults
  digitalWrite (SS, LOW);
  SPI.transfer (DECODE_MODE);  
  SPI.transfer (0x00);  // 0x00 - no-decode mode
  digitalWrite (SS, HIGH);

  digitalWrite (SS, LOW);
  SPI.transfer (INTENSITY_ADDRESS);  
  SPI.transfer (0x0F);  // 0x0F - max on/brightness
  digitalWrite (SS, HIGH);

  digitalWrite (SS, LOW);
  SPI.transfer (SCANLIMIT_ADDRESS);  
  SPI.transfer (0x07);  // 0xFF or 0x07? 0x07 - all display digits on
  digitalWrite (SS, HIGH);

  digitalWrite (SS, LOW);
  SPI.transfer (SHUTDOWN_ADDRESS);  
  SPI.transfer (0x01);  // 0x01 - normal operation mode
  digitalWrite (SS, HIGH);

  digitalWrite (SS, LOW);
  SPI.transfer(DISPLAYTEST_ADDRESS);
  SPI.transfer(0x00);  // 0x00 - normal operation mode
  digitalWrite (SS, HIGH);
  
  //clear display
  for(int group=0; group<totalGroups; group++){    
      digitalWrite (SS,LOW);
      SPI.transfer (registerAddress[group]);  // register to write to
      SPI.transfer (B00000000);  // and value       
      digitalWrite (SS,HIGH);
  }

}

void loop() {   
  //clear display
  for(int group=0; group<totalGroups; group++){    
      digitalWrite (SS,LOW);
      SPI.transfer (registerAddress[group]);  // register to write to
      SPI.transfer (B00000000);  // and value       
      digitalWrite (SS,HIGH);
  }
  
  for(int group=0; group<totalGroups; group++){
    for(int led=0; led<8; led++){
      digitalWrite (SS,LOW);
      SPI.transfer (registerAddress[group]);  // register to write to
      SPI.transfer (registerData[led]);  // and value       
      digitalWrite (SS,HIGH);
      //Serial.println(registerData[led]);
      delay(5);
    }
  }




}