C program Use a button and an LED and write a program to implement the following
ID: 3715632 • Letter: C
Question
C program
Use a button and an LED and write a program to implement the following:
- When the button is pushed and released, the program counts the number of seconds the button was pushed.
- If the button was pushed less than a second, after the button is released it prints the message "The push was not long enough!"
- If the button is pushed more than a second, after the button is released it makes the LED blink. The number of times the LED blinks is equal to the number of seconds the button was pushed.
Explanation / Answer
Solution:
code:
#include<stdio.h> //i/o library
#include <time.h>
int main(){
clock_t start, end;
int pushed_button_time;
int button;
if(button==1){
start = clock();
if()
end = clock();
pushed_button_time = ((double) (end - start)) / CLOCKS_PER_SEC;
}
if(pushed_button_time<1)
printf("The push was not long enough!");
else
while(pushed_button_time>0)
{
blinkLED(); //Thhe function to blick LED can be implemented here.
}
return 0; //This is to make sure that the program terminates
}
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.