need help with arduino program. 3. Start a new sketch and write codes to accompl
ID: 3678497 • Letter: N
Question
need help with arduino program.
3. Start a new sketch and write codes to accomplish the following task: Give an array of 5 arbitrarily float numbers (e.g.. 70.11, -42, 1.0, -5.3, 1465). Use "for" loop and “if" statements to find themaxand the min numbers. Type '0' in Serial Monitor to display the min value in Serial Monitor, and type '9' to display the max number. Display a reminder message to user if any other number or character is being typed, such as "Unexpected input! Please type a number of 0 or 9:" Hint: 1. Define a float array to store the 5 numbers: float myNumbers = { }; 2. Define two float variables, such as "myMaxNum" and "myMinNum" to temporarily store the larger and the smaller numbers when compare any two numbers. You can first temporarily assume the first number is myMaxNum and myMinNum, then later compare it with the rest number to update myMaxNum or myMinNum when needed. MyMaxNum = myNumbersl0l: myMinNum myumbers[01 for lint is), i MyMaxNum) if (myNumbersti]Explanation / Answer
float myNumbers[ ]={70.11,-42,1.0,-5.3,1465}
void setup() {
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop() {
int myNumbers[0]=myMaxNum;
int myNumbers[0]=myMinNum;
if (Serial.available()) {
char Userinput=Serial.read();
if(Userinput=='0' || Userinput=='9')
{
if(Userinput=='0')
{
for(int i=0;i<5;i++)
{
if(myNumbers[i]>myMaxNum)
myMaxNum=myNumbers[i];
}
serial.print(myMaxNum);
}
if(Userinput=='1')
{
for(int i=0;i<5;i++)
{
if(myNumbers[i]<myMinNum)
myMinNum=myNumbers[i];
}
serial.print(myMinNum);
}
}
else
{
serial.println("Unexpected input please type 0 or 9 only!");
serial.println(Userinput);
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.