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

Part 6-Homework Write a program for your MSP430 board to will perform the follow

ID: 2291406 • Letter: P

Question

Part 6-Homework Write a program for your MSP430 board to will perform the following three tasks: 1. Input: Take a character string as user input through the serial interface. 2. Processing: Convert the entire string to lower case, anc 3. Output: Return the processed string to serial output, which will be displayed on your computer monitor Example: If the input character string is, "Here I am", the output should be, "here i am". For serial input and output purpose, you should use the serial monitor feature of the Energia.

Explanation / Answer


char* serialString()
{
static char str[21]; // For strings of max length=20
if (!Serial.available()) return NULL;
delay(64); // wait for all characters to arrive
memset(str,0,sizeof(str)); // clear str
byte count=0;
while (Serial.available())
{
    char c=Serial.read();
    if (c>=32 && count<sizeof(str)-1)
    {
      str[count]=c;
      count++;
    }
}
str[count]=''; // make it a zero terminated string
return str;
}

void setup() {
Serial.begin(9600);
}

void loop()
{
static boolean needPrompt=true;
String userInput;
if (needPrompt)
{
    Serial.print("Please enter inputs and press enter at the end: ");
    needPrompt=false;
}
userInput= serialString();
if (userInput!=NULL)
{
    Serial.print("You entered: ");
    Serial.println(userInput);
    Serial.println();
    userInput.toLowerCase();
    Serial.print("You Lower case String: ");
    Serial.println(userInput);
    Serial.println();
    needPrompt=true;
}
}