String conversion Error

I've made two functions. One (called Read3digits) returns a string, and the other function takes a string as argument. Previously I had these two functions in one but for the sake of readability I've split them in to two functions. Now when I try to compile I get the error

could not convert 'Read3digits' from 'String (*)()' to 'String'

Can someone tell me why my String is suddenly a String(*)() and how do I convert it to a normal String?

Do you think that it might help if you posted your sketch ?
I certainly do

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

#include <SPI.h>
#include <MFRC522.h>
#include <Wire.h>
#include <Adafruit_GFX.h>       // version 1.3.6
#include <Adafruit_SSD1306.h>   // version 1.2.9

#define RST_PIN         9
#define SS_PIN          10

MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance
Adafruit_SSD1306 display(128, 64, &Wire, -1, 400000);  // 400kHz I2C clock

void setup() { 
	Serial.begin(9600);
	while (!Serial);
	SPI.begin();
	mfrc522.PCD_Init();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  delay(100);
  display.clearDisplay();
  display.display();
}

void loop() {
	// Reset the loop if no new card present on the sensor/reader. This saves the entire process when idle.
	if ( ! mfrc522.PICC_IsNewCardPresent()) {
		return;
	}

	// Select one of the cards
	if ( ! mfrc522.PICC_ReadCardSerial()) {
		return;
	}
  IntToDisplay(Read3digits);
}

void IntToDisplay(String str){    //Displays the given string
  display.clearDisplay();
  display.setCursor(0,0);
  display.setTextSize(7 );
  display.setTextColor(1);
  display.print(out);
  display.display();
  delay(200);
}
String Read3digits(){   //Reads 3 bytes from the NFC card and returns it as ASCII values as a string
  MFRC522::StatusCode status;
  byte byteCount;
  byte buffer[18];  
  String out;
  byte i;
    byteCount = sizeof(buffer);
    status = mfrc522.MIFARE_Read(6, buffer, &byteCount);
    }
    // Dump data
      for (byte index = 1; index < 4; index++) {
        i = index;
        out += ((char)buffer[i]);
      }
  mfrc522.PICC_HaltA();
  return out;
}

I've used the Copy for Forum button. Is this the correct way to post code? And this is the code. Thanks in advance.

Yes, and it is also the easiest

  IntToDisplay(Read3digits);

You are not actually calling the Read3digits function

Try

  IntToDisplay(Read3digits());

However, there are other problems
In IntToDisplay() you have

  display.print(out);

but out is not in scope at that point because you declared it in the Read3digits() function. Either make it a global so that it is available anywhere in the sketch or return it from Read3digits() and pass it to IntToDisplay(). In fact, that function is passed a String which you named str which is never used

1 Like

Indeed a simple fix. I also changed out to str. Thank you!