AaronLiddiment / LEDMatrix

FastLED Flexible Matrix Class
101 stars 47 forks source link

Examples not working #1

Closed Leonos closed 8 years ago

Leonos commented 8 years ago

First of all, I would like to thank you for these libraries, I was looking for a way to scroll text on my NeoPixel matrix and I luckily found this repository. It seems a lot of your time went into this so I was surprised that these libraries were not mentioned more than they are. Anyway, I tried several of the LEDMatrix and LEDText examples and found them to be not working for me. First I thought it was because of my setup (led(0) is in the left upper hand corner) but you clearly mentioned MATRIX_HEIGHT could be negative. Finally I found a working example and tried to find out why the others weren't working. In the end I pinpointed it to be caused by the Drawline function. It didn't what it was supposed to do and displayed only one row of leds on the edge. So I dived deeper and noticed that if you shift dy << 16, you will always get 0, because dy is int16_t. When I changed that to int32_t I got my first diagonal line. To completely solve the line drawing issue I also had to make x0 and y0 32 bits.

So, in LEDMatrix.cpp:

void cLEDMatrixBase::DrawLine(int32_t x0, int32_t y0, int16_t x1, int16_t y1, CRGB Col)
{
  int32_t dx = x1 - x0;
  int32_t dy = y1 - y0;*

instead of
*void cLEDMatrixBase::DrawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, CRGB Col)
{
  int16_t dx = x1 - x0;
  int16_t dy = y1 - y0;*

and in LEDMatrix.h the template void DrawLine(int32_t x0, int32_t y0, int16_t x1, int16_t y1, CRGB Col); Thanks again for your incredible work.

BTW, the pacman and tetris examples still don't work but that will be for some other time...

AaronLiddiment commented 8 years ago

This is curious! You are right in one sense but the best way to cure this issue is to cast 'y0' at the time it is shifted. Not sure why it always worked for me, could be that all my deving is done on a teensy which is natively 32bit. What board are you using? I will update the source with a (uint32_t) cast on both y0 & x0 very soon.

AaronLiddiment commented 8 years ago

Can you please try the revised changes to the code I have just posted and let me know if they now work for you? The Tetris and Pacman examples could be failing due to amount of ram available.

Leonos commented 8 years ago

Haha, yes, I am not surprised there's a better way to solve it but I just started with Arduinos and learning c++ in December, so shifting bits, pointers and casting is all new for me. I was already very happy that I managed to solve it for myself. :) I just thought I'd let you know since maybe people are not using your library because of the examples not working. That confused me too at first.

I am using an Arduino Mega 2560 to build a clock like this http://clocktwo.com/info.php?lang=en and want scrolling text to display additional information, like temperature. I will try your update as soon as I get home and then report back.

As for Tetris and Pacman: at least one of them complained about the matrix being in the wrong dimension (mine is 14 wide but minus 13 heigh), but when correcting that I only saw Pacman eating the pill -- the ghost chasing like in your video didn't appear. I assume the Mega has sufficient memory but the sprite bits are fun but not essential in my current project. ;)

AaronLiddiment commented 8 years ago

Don't get me wrong, you did well finding a solution. My assumption was that the compiler would promote the int16's to int32's as the destination variable is int32. It would seem though, that this happens with a 32bit board such as a Teensy but not with 8/16 bit boards. Someone raised an issue about the line draw not working in my original bundled github (RGBLEDS) but I never identified the problem ;) The Pacman demo really needs a wider matrix to work properly, not sure about Tetris though, could be more 8/16 bit board issues...

Leonos commented 8 years ago

:) So it's not a bug that crept in recently... I can imagine that it is hard to be a developer, taking into account all these different board versions and then various led wiring options too. I tremendously appreciate the work you have done because it saved me a lot of thinking, typing and trying. So thanks again.

Anyway, your updated .cpp also works as expected. I am new to GitHub, should I now 'close' this issue or will you?

AaronLiddiment commented 8 years ago

I have used many different C compilers over the years and they all handle variable promotion in different ways! Many thanks for your help in solving this one, i'll remember this for future work :) I'll close this issue now.