Go Down

Topic: How to write text on lcd display when I speak? (Read 137 times) previous topic - next topic

SkyBlue114

Hello I have a question I want to know reason of this

Now my problem is I can't write a text while I speak on lcd display

Code: [Select]

#include <LiquidCrystal.h>

LiquidCrystal lcd(12,11,5,4,3,2);

#define led 13
 String readString = "";
void setup() {
 lcd.begin(16,2);
 pinMode(led, OUTPUT);
 digitalWrite(led, LOW);
 Serial.begin(9600);
}
 
void loop() {
 while (Serial.available()) {
 char c = (char)Serial.read();
 readString += c;
 }
 
 if (readString.length() > 0) {
 
 if (readString == "light on") {
 digitalWrite(led, HIGH);
 lcd.print("Led is on");
 }
 if(readString == "Display"){
  lcd.clear();
  lcd.print("How are you");
 }
 
 
 
 if (readString == "light off") {
 digitalWrite(led, LOW);
 lcd.print("Led is off");
 }
 
 
 readString = "";
 }
 
 delay(100);
}


These are my codes
So While I give "Light on" Command is Running but I give "Display" Command is not working
What is reason of this ?
by the way I 'm new at arduino

PaulS

You are assuming that all the data for a "command" arrives at one time. That is NOT the case.

What is sending the serial data to the Arduino? Can you control HOW it sends the data?
The art of getting good answers lies in asking good questions.

SkyBlue114

well, is this wrong ?

Code: [Select]

char serialA;

void loop() {
 
   if (Serial.available() > 0) {
  serialA = Serial.read();
  lcd.print(serialA);
  digitalWrite(led,HIGH);
  lcd.setCursor(0,1);
  lcd.print("How are you");
  digitalWrite(led, LOW);
 }
}

groundFungus

That code will read 1 byte from the serial port and print to the LCD.  Is that what you expect?

The serial input basics tutorial may be of help to you.

sterretje

If you print the content of readString, you can see what is happening.

Code: [Select]
  Serial.print("readString contains: '");
  Serial.print(readString);
  Serial.print("'");

Place it before the first if in loop() in your code in the opening post.


Robin's tutorial (linked in reply #3) provides a basis for a better approach.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

Go Up