Problems with "call of overload" error :(

Hi guys.

My code is throwing this error over and over again

"exit status 1
call of overloaded 'drawBitmap(int, int, int&, int, int, int)' is ambiguous"

My code is here

#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

static const unsigned char PROGMEM logo1[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x03, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20,
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0 


// I deleted part of the code, but in the end I am defining 3 arrays of pixels for the 3 images



int logo[] = {logo1, logo2, logo3};


const int buttonPin = 2;
int count = 0;   
int buttonState = 0;         
int lastButtonState = 0;  


void setup(){
  
 Serial.begin(9600);
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(2000);


  display.clearDisplay();


 pinMode(buttonPin,INPUT); 

 //  display.drawBitmap(0,-15, logo1, 128,64,WHITE);
   //   display.display();
}

void loop() {

   buttonState = digitalRead(buttonPin);

if (buttonState == HIGH) {
   
  for (count=1;count<3;count++) {
   display.clearDisplay();
        display.drawBitmap(0,-15, logo[count], 128,64,WHITE);
        display.display();
        delay(200);
  }

}
 lastButtonState = buttonState;
 }

You can see that it is a button that shows 3 images. changing it when I press the button.

I don't know how can I make this work !!

  for (count=1;count<3;count++) {

So, iterate while count is 1 and 2, then stop. Hmmm.

The third argument to drawBitmap() is a pointer that is in SRAM. The function expects a pointer that is in PROGMEM. Not the cause of the compiler complaint, but it IS an issue.

The type of values in the array is unsigned char. The type of the array is int. Complete nonsense, and the real cause of the compiler complaint.

The real idea is to iterate 17 times, but the code is too long so Iam testing with 2 iterations.

I don't get to understand how can a I solve this.

Should I declare the arrays without PROGMEM?

And the other question, The array logo is just an array with the names ofthe other arrays, does it need to be
static const unsigned char like the arrays that defines the images?

I tried but throws the same error again

Should I declare the arrays without PROGMEM?

What does the drawBitmap() function expect? A pointer to data in PROGMEM. So, no, you should not. And couldn't, anyway. There isn't enough room in SRAM for one of your bitmaps, let alone 3 (or 17).

What you DO need to do is store the pointers to data in PROGMEM in the right hind of array, in the right place.

static const unsigned char PROGMEM logo1[] = {

This is one of the pointers that you want to store. The TYPE is clearly unsigned char. The static keyword is useless for global variables used in one compilation unit. The const just says that you will not change the data in the array. The PROGMEM keyword says to not copy the data to SRAM at run time. What is left is unsigned char logo1[], which says that logo1 is an array of unsigned chars. Since the address of an array is a pointer to the first element, this declaration could have been:

const unsigned char PROGMEM *logo1 = {

So, it is obvious that, if you are going to store logo1 in an array, the array type must be pointer to unsigned char, NOT int.

Thanks for answering.

As I wrote at the last reply, I tried using

 const unsigned char PROGMEM  logo[] = {logo1, logo2, logo3};

to define the array, but with no success.

I understood everything that you have written but I still get the same error :frowning:

const unsigned char PROGMEM  logo[] = {logo1, logo2, logo3};


const int buttonPin = 2;
int counter = 0;   
int buttonState = 0;         
int lastButtonState = 0;  
int timer = 100;

void setup(){
  
 Serial.begin(9600);
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.display();
  delay(2000);


  display.clearDisplay();


 pinMode(buttonPin,INPUT); 

 //  display.drawBitmap(0,-15, logo1, 128,64,WHITE);
   //   display.display();
}

void loop() {

  buttonState = digitalRead(buttonPin);
  
   if (buttonState != lastButtonState) {

   if (buttonState == HIGH) {
     
     counter++;
     display.clearDisplay();
     display.drawBitmap(0,-15, logo[counter] , 128,64,WHITE);
     display.display();
     delay(200);
       
       if {(counter>4 ) 
     counter=0;
       } 
       }
 lastButtonState = buttonState;

   }

I understood everything that you have written but I still get the same error

Apparently you didn't.

const unsigned char PROGMEM *logo[] = {logo1, logo2, logo3};

It throws an error if I add the "*"

variable 'logo' must be const in order to be put into read-only section by means of 'attribute((progmem))'

That is why I finally didn't write it.

Anyways I have been googling for this error and found that I have to write it like this:

const unsigned char * const logo[] PROGMEM = {logo1, logo2, logo3};

Now it is working. Thanks :slight_smile: