how to read a string and display it, something like a scanf ("% s", string); in C ? but in arduino.
I need to show the message on a 16x2 lcd screen
I would appreciate your response
how to read a string and display it, something like a scanf ("% s", string); in C ? but in arduino.
I need to show the message on a 16x2 lcd screen
I would appreciate your response
The Arduino is programmed in C++ but bear in mind that it does not have a keyboard or screen so C/C++ functions that depend on their use will not work
Take a look at Serial input basics - updated for techniques to receive a string and parse it
Have you got an LCD screen ?
If so, then please post a link to it
String palabra[20];An array of Strings?
All those delay()s are going to create a very unresponsive program.
If you want a responsive program you should not use delay() as the Arduino is blocked until the delay() completes. And for the same reason don't use WHILE or FOR unless they complete very quickly - in a small number of microseconds. Generally it is better to use IF and allow loop() to do the repetition.
The functions delay() and delayMicroseconds() block the Arduino until they complete.
Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.
And see Using millis() for timing. A beginners guide if you need more explanation.
It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. This can happen after the program has been running perfectly for some time. Just use cstrings - char arrays terminated with '\0' (NULL).
...R
I want the message to remain static in this part of the code until I enter a value, but I have to enter both in advance:
lcd.setCursor(0,0);
lcd.print("choose amessage ");
lcd.setCursor(0,1);
lcd.print("1-9:");
delay("3000");
lcd.clear();
num2=Serial.read();
Try what you told me but it doesn't solve it
and I still can't read and show a word on the lcd: C :(. I'm new to Arduino
You didn't post your code.
It's hard to help with code we can't see.
Curious about this as well
premobowei:
Curious about this as well
Which? How to enter strings, or the lack of code?
I already solved the message. I just need to read and show a word, the code is the same as I did before
const byte maxMsgLen = 32;
const byte cbLF = 10;
const byte cbCR = 13;
void setup() {
Serial.begin(250000);
Serial.println(F("use CR as line delimiter"));
}
void loop() {
static uint8_t bIndex;
static char buffer[maxMsgLen + 1];
bool lineReady = false;
if (Serial.available()) {
char inChar = Serial.read();
if (inChar != cbLF) {
if (inChar == cbCR) {
lineReady = true;
} else {
buffer[bIndex++] = inChar;
lineReady = (bIndex == maxMsgLen);
}
if (lineReady) {
buffer[bIndex] = 0;
bIndex = 0;
Serial.print(F("I got the string '"));
Serial.print(buffer);
Serial.println(F("'"));
}
}
}
}
use CR as line delimiter
I got the string 'one'
I got the string 'two'
I got the string 'three'
I got the string 'or a line, up to 32 chars'
I do not understand, you could be more precise is that I am new to this
I gave you a minimalistic example of 'I just need to read and show a word', but I will not spoonfeed you the
UKHeliBob:
Serial input basics - updated for techniques to receive a string and parse it
.