Go Down

Topic: Shifting down LED's (Read 235 times) previous topic - next topic

Pstep

Dec 09, 2018, 11:39 pm Last Edit: Dec 10, 2018, 12:27 am by Pstep
Hey, I have a problem with my code. I need to make a side border that will shift down and create illusion as if it was moving (as in the picture)



That's my code currently but it doesnt work as it's supposed to. Can anyone give me some usefull tips or solutions ?


Code: [Select]
void createNewTopWallBlocks() {
 createNewBlock(0, 0, true);
 createNewBlock(0, 1, false);
  createNewBlock(7, 0, true);
 createNewBlock(7, 1, false);
}

void createNewBlock(int x, int y, bool border) {
  if (border)
    blocks[x][y] = 5;
  else
    blocks[x][y] = 6;


void scrollAllBlocks() {
  for (int y = 5; y >= 0; y--) {
    for (int x = 0; x < 8; x++) {
      blocks[x][y+1] = blocks[x][y];
      blocks[x][y+2]=blocks[x][y+1];


    }
  }
}



void renderBlocks() {
  // AberLED.clear() must have been called before
  for (int x = 0; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
      switch (blocks[x][y]) {
        case 0:
          break;
        case 1:
        case 5:
          AberLED.set(0, y, RED);
          AberLED.set(7, y, RED);
          break;
        case 6:                             
          AberLED.set(0, y, BLACK);
          AberLED.set(7, y, BLACK);
          break;
        default: // anything else must be yellow
          AberLED.set(x, y, YELLOW);
      }
    }
  }
  // AberLED.swap() must be called later
}



https://pastebin.com/Xaa6fbE2

Railroader

That is not the entire code. Use comments, in the code, to tell what the lines of code are intended to do. Then attach the complete sketch.
Use Your knowledge. If that's not enough, look for education.
Having knowledge, think outside the box to gain more of it. Only trains run like the train, on the rails. The rest run between the rails.

TomGeorge

#2
Dec 10, 2018, 12:17 am Last Edit: Dec 10, 2018, 12:21 am by TomGeorge
Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

What model Arduino are you using?
What display are you using? 
Can you post a link to spec/data?

Thanks.. Tom... :)
Everything runs on smoke, let the smoke out, it stops running....

Pstep

Well, it's Arduino Uno R3 with custom University Game Matrix 8x8 Led. The problem is that I'm not allowed to use any other libraries. So basically the LED's need to be shifted down using only loops.

Railroader

In scrollAllBlocks the y-index loops from 5. Is that good? It looks odd to me.
Maybe You should test the various functions one by one to verify proper action. Scrolling means blacking the old and lightin up the new one and handling the wrap around at the bottom. Algorithms like this consist of starting up, running and finishing, or being in sync for a restart.
Use Your knowledge. If that's not enough, look for education.
Having knowledge, think outside the box to gain more of it. Only trains run like the train, on the rails. The rest run between the rails.

TomGeorge

Hi,
What library are you using?
Can you post a link to its source?
Did the library come with examples?
Can you post your complete code?
Are you writing code that just does this scroll only, no other code added?
If not then write some code to just attempt to get the scroll to work.

Thanks.. Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

Railroader

Or send us a crystal ball...… We need more info to take action.
Use Your knowledge. If that's not enough, look for education.
Having knowledge, think outside the box to gain more of it. Only trains run like the train, on the rails. The rest run between the rails.

Slumpert

Seems like you could just alternate a bit additiion and bit shift in a byte variable and input that into your blocks function.  Since rows 0 and 7 seem to be duplicated, even easier.
Psudocode -
Setup
byte Edgebits = 0;
bool Edgestate = 0;
Loop
If Edgestate {
Edgestate ++;
Edgebits ++;
}
Else {
Edgestate ++;
Edgebits << ;
}

Think should fill up a byte with alternating 0s and 1s to use as input for your function.


Go Up