I have a poor driving skill so always I hit the wall whenever I park my car. Sin
ID: 3919642 • Letter: I
Question
I have a poor driving skill so always I hit the wall whenever I park my car. Since your company is the number one Digital design company offering solutions to the above type of problems ( … I need your help in designing a system that will solve this problem). Your company can use the following components:
• An analog sensor to measure the distance between the car and the wall. The sensor gives a voltage between 1V and 10V that is proportional to the distance. If the distance is 10cm, the sensor gives 1V, if the distance is 100cms the sensor gives 10V.
• Three LEDs: green, orange, and red
• PIC16F877 microcontroller which has a 10 bit ADC converter . The green LED is on if the distance is larger than 80cms, the orange LED is on if the distance is between 20cms and 80cms, and the red LED is on if the distance is less than 20cms.
Write a program in C or assembly to operate the system as described
Explanation / Answer
#include <stdio.h>
#include <stdlib.h>
int analogsensor(int distance)
{
if(distance==10)
return 1;
else if(distance==100)
return 10;
}
void microcontroller(int distance)
{
if(distance>80)
printf("Green"); //you can return 1 or 0 from here by using return type in function microcontroller
else if(distance<80&&distance>20)
printf("Orange"); //you can return 1 or 0 from here by using return type in function microcontroller
else if(distance<20)
printf("Red"); //you can return 1 or 0 from here by using return type in function microcontroller
}
int main()
{
int distance=100; //This distance is sense by sensor and takes as an input.
analogsensor(distance);
microcontroller(distance);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.