1
votes

I'm trying to create a sort of number picker. It'll show you 0 to 9 and using an X, which I will write over the number you can choose a number. As an example 01234567x9 or 0123x56789. I'm struggling however with printing this to an LCD. I'm using a tinkercad so all of my pin connections are predefined and pretty much correct. I'm using the standard tinkercad LCD and LiquidCrystal as a library.

But when I use lcd.print("Hello World) in void loop() it continuously prints Hello World, obviously because I put it in a loop. I've tried to put it in a function but I can't quite get it to work... Some help would be perfect.

This is the code I'm currently using, it returns "too many arguments to function 'void PrintText()'" as an error.

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char lcdtxt[] = "0123456789 x";

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
 
}
void PrintText(){
   lcd.print(lcdtxt);
   lcd.clear();
  }
void loop() {
  PrintText(lcdtxt);


}
1
This doesn't look like it should have the C# tag. - Matthew Watson
define a "setMessage" function that can Set the value of the variable "lcdtxt" - ΦXocę 웃 Пepeúpa ツ

1 Answers

2
votes

Seeing your code, you have a global char array that holds what is going to be written, and PrintText() will take its input from there:

char lcdtxt[] = "0123456789 x";

void PrintText(){
   lcd.print(lcdtxt);
   lcd.clear();
  }

void loop() {
  PrintText(lcdtxt);
}

So, PrintText() won't take any arguments, and you're calling it with one. In this case the error message is telling you exactly what is happening.

To fix your code, you should only remove the parameter to the `PrintText()' call, since I understand you have already initialized the array.

void loop() {
  PrintText();
}

You should define a PrintText() function accepting a const char * and send that to the LCD, anyway.

About hello world repeating itself continously, I'd move the call to PrintText() to setup(), since you don't need that behaviour. Or maybe leaving it in loop() and stopping by means of an exit(0).