Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Arduino does not allow you to do a printf() statement to the terminal which can

ID: 3891870 • 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 Sensor1 = 12;

int Sensor2 = 15

int Sensor3 = 10

char array[100];

void setup() {

Serial.begin(10000);

sprintf(array, "Wall Sensor 1 = %d cm. Wall Sensor 2 = %d .Wall Sensor 3 = %d cm.",Sensor1,Sensor2,Sensor3);

Serial.println(array);

}

void loop() {

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote