[SOLVED] Needing a "reverse pixels" function for my ucglib / ST7735S display

I'm using the usglib Universal uC Color Graphics Library to run my ST7735 Display.

When my project is in idle-mode, the screen displays an analog clock face. The hands of the clock are on top of a background image, so each minute I update the clock by redrawing the image and then the hour and minute hands over the image.

I would like to add a second hand, but redrawing the image each second to do so is not reasonable.

On my PC, there is a function called ReversePixels() which makes moving a hand easy. I just draw the hand with ReversePixels() over the background. Then to move the hand, I draw in the same location again with ReversePixels() which makes the hand disappear by reversing all pixels back to what they were before I first drew the hand. Then I call ReversePixels() again at the hand's new location. (Redrawing the background image is never necessary.)

However, I don't see a ReversePixels() type of function to use on my Arduino project. Does anyone know a way to do this so I can add the second hand?

You won't find such a function in any [u]arduino[/u] library. To do what you are asking would require a good amount of memory, which your average arduino does not have. You would basically need a pixel map (2D array) and store each color in an integer, then go through that array and change the pixels accordingly.

Now the easiest way, that many do, is to just keep a copy of the old coordinates and when you update the clock, you draw the old coordinates first with the background color then you draw the new coordinates.

HazardsMind: ... what you are asking would require a good amount of memory, which your average arduino does not have.

...you draw the old coordinates first with the background color then you draw the new coordinates.

I thought the memory issue might be the problem. And since I'm using a complex background, I can't paint the hand in the background color either. So, I just have to accept it can't be done.

The alternative I'm using is to update the seconds as a number in the lower right corner once a second. :)

I would like to add a second hand, but redrawing the image each second to do so is not reasonable.

You could set the clip range (setClipRange) to a rectangle which covers the old and the new position of the "hand". Then just redraw background and the hand at the new position. At least the amount of data transfered to the display will be reduced a lot and the (re)draw speed will be much higher.

Oliver

Edit: I just noticed the old ucglib link. Ucglib has moved to github meanwhile (google code is closing...): https://github.com/olikraus/ucglib/

Oliver's solution is pretty easy. i.e. redraw the smallest rectangle. Even 128x128 is still quite few pixels for the whole clockface. But at 4.30 you only have to redraw 64x64. At 6.00 you only need 2x64.

Your display is possible to read but it is a bit fiddly. And I don't think u8glib supports readPixel(). If you read the contents of the 64 pixels where you want to draw the second hand, you can draw them back before you draw the next position. 64 pixels is not unreasonable to store in SRAM.

David.

olikraus: You could set the clip range (setClipRange) to a rectangle which covers the old.... Then just redraw background and the hand at the new position.

Oliver

david_prentice: Oliver's solution is pretty easy. i.e. redraw the smallest rectangle.

David.

What an excellent idea! I've partly coded it already, and tested the code in my sketch, and it really works!

Thanks a bunch guys!

olikraus: I just noticed the old ucglib link. Ucglib has moved to github meanwhile (google code is closing...): https://github.com/olikraus/ucglib/

Thanks to you, I've updated my link now to be sure I can continue to access it.

"Google Code" is closing? How sad. That's like when they closed "Google Gears", also a real disappointment and frustration since I'd been working with "Gears" rather extensively, intending to share it with the world. And Google had talked up "Gears" so prowdly, as if it were the foundation upon which the future will be built! Why do these things happen?

"Google Code" is closing? How sad.

Yes, a nightmare, especially for spare time projects like ucglib and u8glib. It took me months to port my projects and i am still not finished. Not only that i had to move from hg to git, but also the documentation had to be migrated from google wiki to markdown. And also release procedures are completly different.

But I feel better, when I see that these projects are useful to others :)

Oliver