Arduino does not allow you to do a printf() statement to the terminal which can
ID: 2294067 • Letter: A
Question
Arduino does not allow you to do a printf() statement to the terminal which can make things difficult to output. To make this easier, create a program that uses sprintf() to print data to a string. That string should then be printed out using a single Arduino’s Serial.Print() command.
As an example, if you have three wall sensors with three ints to print out, you want your output to look like this:
Wall Sensor 1 = 12 cm.Wall Sensor 2 = 15 cm.Wall Sensor 3 = 10 cm.
Where 12, 15, and 10 are all ints that are converted into the above long string using sprintf().
Explanation / Answer
int wallSensor1 = 12;
int wallSensor2 = 15;
int wallSensor3 = 10;
void setup() {
Serial.begin(9600);
}
void loop() {
char buffer[100];// take buffer size as long as the string size.
sprintf(buffer, "Wall Sensor 1= %d cm. Wall Sensor 2= %d cm. Wall Sensor 3= %d cm. ", wallSensor1,wallSensor2,wallSensor3);
Serial.println(buffer);
}
// Like is Expacted. Thank you
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.