0

I am trying to display the output hello 3. How can i achieve this with Serial.print() method defined in SoftwareSerial.h library. I have the following code.

#include <SoftwareSerial.h>

int a = 3;
void setup(){
    Serial.begin(9600);
    Serial.print("hello"+a);
}

void loop(){


}
wokoro douye samuel
  • 2,194
  • 3
  • 15
  • 29

2 Answers2

0

The easiest way is with multiple invocations. That way you don't have to worry about type conversion.

Serial.print("hello");
Serial.print(a);
Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0
void setup(){

    Serial.begin(9600);
    string somestring = "hello" + " " + "3";
    Serial.print(somestring);
}
goto
  • 7,908
  • 10
  • 48
  • 58
Yajie Niu
  • 11
  • 4