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

I am trying to use the Mbed compiler and Mbed.h library with a FRDM-KL46Z microp

ID: 3817699 • Letter: I

Question

I am trying to use the Mbed compiler and Mbed.h library with a FRDM-KL46Z microprocessor

(PLEASE USE C LANGUAGE PREFERRABLY, OR C++)

In one competition, the robot was required to use a color sensor to distinguish one object from another object. The color sensor returned three analog values on three wires. The first signal represented the amount of red seen. The second wire represented the amount of green seen. The third wire represented the amount of blue seen. The voltage levels on the three analog signals are bounded to ov-2.5V. Assume red is on pin PTB0, green on PTB1, and blue on PTB2. You are to write a program, including any necessary subroutines or interrupts, that will update a global variable called "object type" at least 10 times per second. If the colors seen are 70% of maximum red, 30% of maximum green and 10% of maximum blue, all within 5% of maximum on each channel, the object type should have a value of 1. If the colors seen are 40% of maximum red, 80% of maximum green and 70% of maximum blue, all within 5% of maximum on each channel, the object type should have a value of 2. If red, green, and blue are all below 10% of maximum or all above 90% of maximum, the object type should have a value of 0. In any other case, the object type should have a value of -1.

Explanation / Answer

int colorsens( int r,int g,int b)

{

if(r<=70 && g<=30 &&b<=10

{return 1;}

else if(r<=40 && g<=80 &&b<=70

{return 2;}

else if(r<=10 && g<=10 &&b<=10 || r>=90 && g>=90 &&b>=90

{return 0;}

else

return 0;

}

int main()

{ int r,b,g,object_type

cout<<"enter the color percentage for red green and blue";

cin >>r>>g>>b;

object_type=colorsens(r,g,b);

cout <<"It is "<<object_type;

return 0 ;

}

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