call of overloaded 'print(void (&)())' is ambiguous

Hey! For some reason, I'm getting this error message:

call of overloaded 'print(void (&)())' is ambiguous

I'm building a (non-functioning) Star Trek tricorder.

I'm using an LCD screen, and I've got a menu with scanning modes all set up.

However, one of my scanning modes isn't working...

I'm trying to create a scanning mode that will "scan" for your position (give you a random number, plus North, South, East, or West).

Here's my code:

void randPos(){
** randomSeed(analogRead(15));**
** int scanResults = random(0, 3);**
** if (scanResults == 0) {**
** Serial.println("North");**
** }**
** else if (scanResults == 1) {**
** Serial.println("South");**
** }**
** else if (scanResults == 2) {**
** Serial.println("East");**
** }**
** else if (scanResults == 3) {**
** Serial.println("West");**
** }**
}

case 3:
** scanMode();**
** lcd.print ("Position scan ");**
** lcd.setCursor(0,1);**
** lcd.print("initiated");**
** ledDelay();**
** lcd.print(".");**
** delay(800);**
** lcd.print(".");**
** delay(800);**
** lcd.print(".");**
** ledDelay();**
** scanMode();**
** lcd.print ("Position scan ");**
** lcd.setCursor(0,1);**
** lcd.print("completed");**
** ledDelay();**
** scanMode();**
** lcd.print ("Global Position: ");**
** lcd.setCursor(0,1);**
** lcd.print(scanResults);**
** lcd.setCursor(1,1);**
** lcd.print(".");**
** lcd.setCursor(2,1);**
** lcd.print(scanResults);**
** lcd.setCursor(4,1);**
** lcd.print(randPos);**

** //Call the function that belongs to Option 3**
** break;**

However, on the line that says lcd.print(randPos); it's giving me this error:

exit status 1
call of overloaded 'print(void (&)())' is ambiguous

Any and ALL help is GREATLY appreciated!

Thanks!

ALL help is GREATLY appreciated!

Seeing ALL of your code (in code tags) would be appreciated.

In the meantime, why are you trying to print the address of a function that does not even return a value ?

You can't print a function. You can print a String or a char array that a function produces in some way.

Thanks! :slight_smile:

quilkin:
You can't print a function. You can print a String or a char array that a function produces in some way.

Thanks! I've been banging my head why I couldn't. It's just a not-taught rule in Arduino. Just like you can't refer to digitalRead(pin) when pin is an array.

Just like you can't refer to digitalRead(pin) when pin is an array.

No surprise there, surely

UKHeliBob:
No surprise there, surely

UKHeliBob:
No surprise there, surely

Serial.write will I recall. It's an oddball. If you have pin numbers in an array, no matter the type, you can't use them for digitalRead and that really made my day a I'm glad I have a sturdy desk or weak punch.

mattlogue:
Serial.write will I recall. It's an oddball. If you have pin numbers in an array, no matter the type, you can't use them for digitalRead and that really made my day a I'm glad I have a sturdy desk or weak punch.

So you say this code will not compile !

int pins[] = {1,2,3,4,5};

void setup() {
 for (int i = 0; i < 5; i++)
 {
   pinMode(pins[i], INPUT);
 }
}

void loop() {
 for (int i = 0; i < 5; i++)
 {
   int v = digitalRead(pins[i]);
 }
}

Edit : The 'int' array of pin number can be replaced by a 'float' or 'double' array and the code still compiles.

quilkin:
You can't print a function. You can print a String or a char array that a function produces in some way.

print(function()) is perfectly valid providing function() returns a value. print(function) is always valid.

If you have pin numbers in an array, no matter the type, you can't use them for digitalRead

Nonsense.

Please post a program demonstrating that it does not work.