Go Down

Topic: Big RGB Table Finally Needs Code (Read 5 times) previous topic - next topic

CrossRoads

Can give it a shot a little later.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Paranemertes

Thanks CrossRoads, id really appreciate it.
"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

CrossRoads

Ok, maybe something like this
Code: [Select]

#include <SPI.h>

// code for an 36 x 24 array (12 RGB LEDs, 24 columns) as an example
// not all code parts shown, just the highlights
// set up an array for the cathode drives
byte cathodeslower[ ] = {
  0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  // walking 1 for lower 8 NPNs
byte cathodesmid[ ] = {
  0,0,0,0,0,0,0,0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0,0,0,0,0,0,0,0}; //walking for mid 8 NPNs ????????
byte cathodeshigher[ ] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80};  // walking 1 for upper 8 NPNs
 
byte anodes1 [12]; // array to hold 1st 3rd of RGB info, like red?
byte anodes2 [12]; // array to hold 2nd 3rd of RGB info, like blue?
byte anodes3 [12]; // array to hold 3rd 3rd of RGB info, like green?
byte columncount;
byte oe = 12;
unsigned long updateTime = 0;
unsigned long exampleTime = 0;
byte  Red = 0; // arrays go from 0 to 11
byte  Green = 12;
byte  Blue = 12;

void setup(){
  pinMode (oe, OUTPUT);
  digitalWrite (oe, HIGH);
  SPI.begin;

}

void loop(){
  // set up for blink without delay operation
  if (millis() >=updateTime){
    // yes, set up for next update
    updateTime = updateTime +2; // update a column every 2 milliseconds, 16 columns at ~24 Hz rate
    digitalWrite (oe, HIGH);  // turn off display
    SPI.transfer (anodes1[columncount]); // update anodes
    SPI.transfer (anodes2[columncount]); // update anodes
    SPI.transfer (anodes3[columncount]); // update anodes
    SPI.transfer (cathodeslower[columncount]); // turn on a cathode
    SPI.transfer (cathodesmid[columncount]); // turn on a cathode
    SPI.transfer (cathodeshigher[columncount]); // turn on a cathode
    digitalWrite (oe, LOW);  //turn display back on
      columncount = columncount + 1; // update for next column
    if (columncount == 24){
      columncount = 0;
    } // reset if reach the end
  } //end display refresh

  // now the fun part, for you!
  // read buttons, or whatever processing you plan to do for patterns, etc.,
  // and update anodes1, anodes2, anode3 as needed
  if (millis() >= exampleTime){
    exampleTime = exampleTime + 500; // 1/2 second changes
    if (Red < 12){
      anodes1[Red] = 0; // turn off prior LED
      Red = Red + 1; // set up for next LED
      if (Red == 12){  // if at last LED, set up next color
        Blue = 0;
      }
      else {
        anodes1[Red] = 1; // turn on next LED
      }
    }
    if (Blue<12){
      anodes2[Blue] = 0;
      Blue = Blue + 1;
      if (Blue == 12){
        Green = 0;
      }
      else{
        anodes2[Blue] = 1;
      }
    }
    if (Green <12){
      anodes3[Green] = 0;
      Green = Green + 1;
      if (Green == 12){
        Red = 0;
      }
      else{
        anodes3[Green] = 1;
      }
    }
  }

} // end void loop
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Paranemertes

Thanks, I'll give it a try tomarrow.
"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Paranemertes

PHEW. ok sorry about the delay, lots of stuff to do and all that. I FINALLY got some lights on! (just spend 2 1/2 hours doing some trial and error and working my way up on code) Minus 2 leds that need replacing and what i think to be a MOSFET that might be troubled, it works perfectly! you can see in the pics the column that needs replacing, and the 2 leds that are out, one has a blue out, the other has a red. Unfortunately your code didnt work... I tried some manipulations but i really dont know what i am doing, its like trying to build the Eiffel Tower out of legos while wearing boxing gloves. But hey, who doesnt love to learn? I worked my way up to this code:

Code: [Select]
#include <SPI.h>

const int oe = 10;

byte chip1 = 0xFF;
byte chip2 = 0xFF;
byte chip3 = 0xFF;
byte chip4 = 0xFF;
byte chip5 = 0xFF;

unsigned int time = 500;

void setup(){
  SPI.begin();
  pinMode(oe, OUTPUT);
  digitalWrite(oe, LOW);
}

void loop(){
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x80);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x40);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x20);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x10);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x08);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x04);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x02);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x01);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
 
  SPI.transfer(0);
  SPI.transfer(0x80);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x40);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x20);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x10);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x08);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x04);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x02);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x01);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
 
  SPI.transfer(0x80);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x40);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x20);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x10);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x08);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x04);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x02);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x01);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
}


Ewwwww, isnt that gross?? Do you know a basic way to shorten it? Fortunately the SPI is working, i started
with shiftOut(), but there was a ton of flickering, i tried messing with the output enabler, but no good.

now then; what suggestions do you have for learning how to make more complicated animations? Your code seems like it would work, and i have a BASIC understanding of it. Maybe you could revise it? I'll keep trying to expand my knowledge and fix those minor hardware issues. Thank you so much for all your help so far! and thanks for directing me towards the SPI,
Quote
none of that shiftOut nonsense

great advice.
"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Go Up