Reference no: EM132153472
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.