Using energia software Write a program for your MSP430 board to will perform the
ID: 2291455 • Letter: U
Question
Using energia software
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, and 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. Note: After completing your homework, make a video of your work with verbal explanations. Make sure your face is seen in the video. If your LaunchPad or Serial Monitor is not responsive when the TA comes to check your homework, show the TA your video.
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;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.