i am trying to send a string via Bluetooth to a Arduino to be printed on a 16x2 LCD where this string is stored in a variable so that a servo motor get in action based on the string that is stored in a variable
Request for member 'startsWith' in 'Serial.HardwareSerial::read()', which is of non-class type 'int'
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
bool one_time;
#define data Serial.read()
String data_on = "hfg";
#define led 8
void setup(){
lcd.init();
lcd.backlight();
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
one_time = true;
if (Serial.available()) {
delay(100);
lcd.clear();
while (Serial.available() > 0) {
lcd.write(data);
}
if(data.startsWith(data) and one_time == true) {
lcd.print(data);
digitalWrite(led, HIGH);
}
}
}
Hi,
Very good, it should work, or not........
I recommend you read: How to get the best out of this forum
no its not working yet
I need help solving it
Code snippets are worthless.
Post your code. Post the whole program. Read the forum guidelines to see how to properly post code and some information on how to get the most from this forum.
Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.
Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.
In function 'void loop()':
sketch_may16b:25:15: error: request for member 'startsWith' in 'Serial.HardwareSerial::read()', which is of non-class type 'int'
if(data.startsWith(data) and one_time == true) {
^~~~~~~~~~
exit status 1
request for member 'startsWith' in 'Serial.HardwareSerial::read()', which is of non-class type 'int'
That reduces to data.startsWith(Serial.read())
Serial.read() returns an int. The startsWith function requires a String argument.
can you tell me what is the function
What does that mean?
I am sorry but I didn't get the last reply i have tried data.startsWith(Serial.read())
but it didn't work
What I tried to tell you is that the startsWith function will not work with Serial.read() as an argument. Functions take certain data types as their arguments. The startsWith function requires a String as an argument. Serial.read() returns an int data type, not a String.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.