Having a problem passing a string, or text, to a function. Basically I am trying to write a reusable function to print different values when called.
void setup() {
String startStringOne = "This is some text I want to pass to the function";
String startStringTwo = "This is some different text I want to pass to the function";
}
void loop() {
sendThisToTheDisplay (startStringOne, "LED_GREEN");
delay(10000);
sendThisToTheDisplay (startStringTwo, "LED_RED");
}
void sendThisToTheDisplay (sendThisString,showThisColor) {
<some code here for LEDs to display the text string in the color I want>
}
sketch_mar10a.ino:4: error: variable or field 'sendThisToTheDisplay' declared void
sketch_mar10a.ino:4: error: 'sendThisString' was not declared in this scope
sketch_mar10a.ino:4: error: 'showThisColor' was not declared in this scope
sketch_mar10a.ino: In function 'void loop()':
sketch_mar10a.ino:8: error: 'startStringOne' was not declared in this scope
sketch_mar10a.ino:8: error: 'sendThisToTheDisplay' was not declared in this scope
sketch_mar10a.ino:10: error: 'startStringTwo' was not declared in this scope
sketch_mar10a.ino: At global scope:
sketch_mar10a.ino:14: error: variable or field 'sendThisToTheDisplay' declared void
sketch_mar10a.ino:14: error: 'sendThisString' was not declared in this scope
sketch_mar10a.ino:14: error: 'showThisColor' was not declared in this scope
However.. In my final code (see below), the library requires an argument to specify the color, this will also need to be specified within the function call within the loop function.
But it throws an error when I run it. Seems the setTextColor argument requires a uint16_t. The allowed values look like this:
setTextColor(LED_GREEN)
setTextColor(LED_RED)
setTextColor(LED_YELLOW)
If I were to remove the second argument in my function call and write the setTextColor properly, then all the code works fine. But I need to be able to specify which color I am using
Error
I2C_Multiple_LED_Displays.ino: In function 'void doTextScroll(String, const char*)':
I2C_Multiple_LED_Displays.ino:33: error: invalid conversion from 'const char*' to 'uint16_t'
I2C_Multiple_LED_Displays.ino:33: error: initializing argument 1 of 'void Adafruit_GFX::setTextColor(uint16_t)'
I'd say there's a good chance that LED_GREEN is actually a #define or a const value that would be found in the library.
Try putting a line in setup() to serial.print(LED_GREEN) and you'll probably get a value that would make an RGB LED green. It's unlikely that a function that displays an RGB LED would take a string for a value.