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: 3907768 • 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

char *CreateString(int a, int b, int c){
   char str = (char *) malloc(sizeof(char) *100);
   sprintf(str,"Wall Sensor1 = %d cm. Wall Sensor 2 = %d cm.Wall Sensor3 = %d    cm",a,b,c);
   return str;
}

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