I'm trying to display random noise on one of those I2C 0.91 inch 128x32 OLED screens and with my current code I seem to have so much overhead that I can only refresh it about every 450 ms.
Right now I'm using an Arduino Uno for development, but ideally I'd later convert it for use on an ATTiny.
Any chance that someone could point me in a direction of how I can optimize my code to get more refreshes per second out of it? Purpose of this is for a small table-top Star Wars droid.
First off. You should use W, H arguments in the constructor.
You have chosen a convoluted way to create random pixels. i.e. 8192 calls to rand()
Note that your cut-price constructor expects 128x64 screen.
Since a 128x32 screen uses a 512 byte buffer, you could just call random() 512 times using a range of 0, 255 and store each 8-pixel byte directly in the buffer.
david_prentice:
Since a 128x32 screen uses a 512 byte buffer, you could just call random() 512 times using a range of 0, 255 and store each 8-pixel byte directly in the buffer.
Thanks!
That sounds a lot more efficient.
I'm not sure how to populate the buffer directly, but your advice and a look at the documentation already brought me a lot closer, practically halved the execution time per frame.
Had to define the bitmap array in the utility function, because defining it at the top led to "image_generator:11:35: error: array bound is not an integer constant before ']' token".
I want to keep it as flexible as possible, so I'm not hardcoding the width/height/buffer size.