Hi there,
Based on this example from Adafruit (the testdrawbitmap function around the middle):
[tried to post the code but it exceeds maximum character count - just check Adafruit SSD1306 library and the example from that custom library namely the 128x64 spi one.]
... I am trying to use arrays for graphic effects. This is my code, skip to the functions on the very bottom.
void screensaver1(const uint8_t *bitmap, uint8_t w, uint8_t h)
{
int Xdir = 1;
int Ydir = 1;
int f = 1;
int SSFRAMES = 2640;
uint8_t icons[NUMFLAKES][3];
icons[f][XPOS] = random(display.width() - w);
icons[f][YPOS] = random(display.height() - h);
icons[f][DELTAX] = (Xdir) * (random(2,4) + 1);
icons[f][DELTAY] = (Ydir) * (random(2,4) + 1);
while (1) {
for (int n = 0; n < SSFRAMES; n++)
{
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, WHITE);
display.display();
delay(200);
display.drawBitmap(icons[f][XPOS], icons[f][YPOS], bitmap, w, h, BLACK);
if (Xdir == 1) {
if ((icons[f][XPOS] + icons[f][DELTAX]) > (display.width() - w))
{
icons[f][XPOS] -= icons[f][DELTAX];
Xdir = -1;
}
else icons[f][XPOS] += icons[f][DELTAX];
}
else if (Xdir == -1) {
if ((icons[f][XPOS] - icons[f][DELTAX]) <= 0)
{
icons[f][XPOS] += icons[f][DELTAX];
Xdir = 1;
}
else icons[f][XPOS] -= icons[f][DELTAX];
}
if (Ydir == 1) {
if ((icons[f][YPOS] + icons[f][DELTAY]) > (display.height() - h))
{
icons[f][YPOS] -= icons[f][DELTAY];
Ydir = -1;
}
else icons[f][YPOS] += icons[f][DELTAY];
}
else if (Ydir == -1) {
if ((icons[f][YPOS] - icons[f][DELTAY]) <= 0)
{
icons[f][YPOS] += icons[f][DELTAY];
Ydir = 1;
}
else icons[f][YPOS] -= icons[f][DELTAY];
}
}
}
}
void pixelstorm()
{
for (int q = 0; q < 30000; q++) {
int xpos = random(display.width());
int ypos = random(display.height());
display.drawPixel(
}
}
void droplets()
{
uint8_t drops[NUMDROPS];
for (uint8_t f = 0; f < NUMDROPS; f++)
{
drops[f][XPOS] = random(5,(display.width()-5));
drops[f][YPOS] = random(5,(display.height()-5));
drops[f][DELTA] = random(4,7);
drops[f][RADIUS] = 1;
}
while (1)
{
for (int i = 0; i < 100; i++)
{
for (uint8_t f = 0; f < NUMDROPS; f++)
{
display.drawCircle(drops[f][XPOS], drops[f][YPOS], drops[f][RADIUS], WHITE);
if (drops[f][RADIUS] > (drops[f][DELTA] + 1)
{
display.drawCircle(drops[f][XPOS], drops[f][YPOS], (drops[f][RADIUS]-drops[f][DELTA]), WHITE);
}
if (drops[f][RADIUS] > (2 * (drops[f][DELTA]) + 1)
{
display.drawCircle(drops[f][XPOS], drops[f][YPOS], (drops[f][RADIUS]-(2*(drops[f][DELTA]))), WHITE);
}
}
display.display();
delay(200);
for (uint8_t f = 0; f < NUMDROPS; f++)
{
display.drawCircle(drops[f][XPOS], drops[f][YPOS], drops[f][RADIUS], BLACK);
if (drops[f][RADIUS] > (drops[f][DELTA] + 1)
{
display.drawCircle(drops[f][XPOS], drops[f][YPOS], (drops[f][RADIUS]-drops[f][DELTA]), BLACK);
}
if (drops[f][RADIUS] > (2 * (drops[f][DELTA]) + 1)
{
display.drawCircle(drops[f][XPOS], drops[f][YPOS], (drops[f][RADIUS]-(2*(drops[f][DELTA]))), BLACK);
}
drops[f][RADIUS]++;
}
if (drops[f][RADIUS] >= 90)
{
drops[f][XPOS] = random(5,(display.width()-5));
drops[f][YPOS] = random(5,(display.height()-5));
drops[f][DELTA] = random(4,7);
drops[f][RADIUS] = 1;
}
}
}
}
}
void matrixletters()
{
int xpos = random(display.width());
}
Again, this is just an excerpt.
I learned most by experimenting, but with this I can't really get why I get the 'expected primary-expression before "{"token' error.
Also to be honest neither how exactly arrays are declared, it's not fully explained on the arduino page for them and I don't really know where to look to get a handle on these matters.
The goal with the raindrops function is that at random positions a 'ripple' expands as a circle followed by 2 smaller ones.
Can you help point me in the right direction so that I can teach myself, or explain and/or help fix my code? I'd appreciate it a lot!