Hello! I'm trying to make a very simple animation using an OLED display, but the delays don't seem to, well, delay. Are there any other ways I should do this? This is the code:
When using a new library, it is a good idea to look over the documentation, and try out some of the examples in the library, before trying random bits of code.
Is it possible that your chosen library doesn't draw background colour pixels when it writes to the screen, but only draw foreground colour pixels? That would account for the effect you seem to be seeing.
Notice that you call draw() an unknown number of times. The call to firstPage() initialises a process for calling nextPage() as many times as it takes to paint the entire display.
draw() should be as fast as possible, and written to paint the entire display. Which it will accomplish by being called N times.
void loop() {
screen.firstPage();
do {
draw();
} while(screen.nextPage());
}
It is inappropriate and just won't work to expect delay() in the draw method to do anything like it does when you talking about blinking some LEDs.
Rewrite draw() so it paints a frame of animation, then the next time you launch the firstPage/nextPage dance, draw() should paint the new frame.
Space out your launches of the hole thing with delay() if you must. Draw the '#' the first time, don't draw it the second time and so forth.
It just means doing the work a bit differently. You can get displays that will immediately reflect the effects of calls to draw characters or whatever. It is also possible that another library would take that traditional approach - the first/next thing is done to reduce the RAM required, and is more important for limited RAM and/or large displays.
What qualifies as limited and large vary with the circumstances.
if ( blink == 1 ) ...... else blink must be 0, there's no need to ( check ).
Memory in AVR's is tight and people work by habit. On Arduino, make an effort to store small numbers like pin numbers and t/f flags should be in unsigned 8 bits IMO.
Please one thing about delay() use. Finding a way to get around this took time and effort and you still have periods where no inputs like bottons or sensors can be read and acted on. Help on the subject is like a forum specialty, learning to fly.