Instructables

editing LED matrix code help?

Hi All,

For a while now I've been working on a pair of LED matrix glasses. I've been following this instructable to guide me in the right direction.
The code used in this instructable is ok but I want to add something to it (but don't know how obviously).
I would like the code to pick a random animation (from one of the preprogrammed animations) and play it a random amount of times.
It should also be possible to play the next animation by the press of a button.
The maximum and minimum amount of times to play an animation will be predeterment (separately for every animation).
If possible but I think this will be tricky, it would be nice to have a transition animation when switching animations.

What I've got so far is:

//test random animation script

int TotAnim = 4;              //totaal animations

int LoopTime = 1;             //times to reapeat the animation randomly selected
long AnimNumb;                //animation number randomly selected
int LoopCount = 0;            //times the animation played
int MaxLoop = 10;             //variable to store maximum times to repeat animation
int MinLoop = 20;             //variable to store minimum times to repeat animation
int FrameTime = 4;            //variable to store the times to play 1 frame
int Frames = 10;              //variable to store the amount of frames of the selected animation
char AnimName;                //stores the selected animation name

void setup(){
  Serial.begin(9600);
  randomSeed(analogRead(0));
}

void loop(){
if (LoopTime != LoopCount){
    LoopCount += 1;
  //for testing
  Serial.print(" loop times: ");
  Serial.print(LoopTime);
  Serial.print(" loop count: ");
  Serial.print(LoopCount);
  Serial.print(" animation: ");
  Serial.print(AnimNumb);
  Serial.print(" frames: ");
  Serial.println(Frames);
  Serial.print("run_animation_p(");
  Serial.print(FrameTime);
  Serial.print(", ");
  Serial.print(AnimNumb);
  Serial.print(", ");
  Serial.print(Frames);
  Serial.print(", ");
  Serial.print(LoopTime);               //LoopTimes might have to be 1 in the "run_animation_P(12, rotatebox_P, 4, 30);"
  Serial.print(");");
  delay(70);
}
else if (LoopTime == LoopCount){
  LoopCount = 0;
  AnimNumb = random(1, TotAnim);
  switch (AnimNumb){
    case 1:                            //animation number
//    AnimName = rain                    //name of the animation
    MaxLoop = 20;                      //maximum times to repeat the loop
    MinLoop = 5;                       //minimum times to repeat the loop
    Frames = 10;                       //amount of frames of the animation
    FrameTime = 1;                     //times to play 1 frame
    goto next;                         //goto the next part
    break;
   
    case 2:                            //animation number
//    AnimName = rotating_box            //name of the animation
    MaxLoop = 30;                      //maximum times to repeat the loop
    MinLoop = 30;                       //minimum times to repeat the loop
    Frames = 20;                       //amount of frames of the animation
    FrameTime = 2;                     //times to play 1 frame
    goto next;                         //goto the next part
    break;
   
    case 3:                            //animation number
//    AnimName = test                    //name of the animation
    MaxLoop = 50;                      //maximum times to repeat the loop
    MinLoop = 30;                       //minimum times to repeat the loop
    Frames = 30;                       //amount of frames of the animation
    FrameTime = 3;                     //times to play 1 frame
    goto next;                         //goto the next part
    break;
   
    case 4:                            //animation number
//    AnimName = test2                   //name of the animation
    MaxLoop = 25;                      //maximum times to repeat the loop
    MinLoop = 2;                       //minimum times to repeat the loop
    Frames = 40;                       //amount of frames of the animation
    FrameTime = 4;                     //times to play 1 frame
    goto next;                         //goto the next part
    break;  
  }
    next:
    LoopTime = random(MinLoop, MaxLoop);
}

}

I'm not a good coder BUT what you see up here works!
The only thing is, I can't get this into the original code.

Can someone help me with the code?

frollard1 year ago
While I can't comment directly to the other code without doing a tonne of digging, you need to modify that code so that instead of just looping one animation, the 'loop animation' part of the code points to some data based on a function argument, not just 'the same data every time'...

That way, your code will work to call on the random frames to display.
theexternaldisk (author)  frollard1 year ago
thanks for the help I'll give it a try!
Pro

Get More Out of Instructables

Already have an Account?

close

PDF Downloads
As a Pro member, you will gain access to download any Instructable in the PDF format. You also have the ability to customize your PDF download.

Upgrade to Pro today!