4 20 pts Write a complete C program that performs the follow

4. [20 pts] Write a complete C program that performs the following sequence Asks user to enter a number between 0 and 9 Identifies whether the number entered is EVEN or ODD (using only bitwise operators) If number entered is EVEN Turn the on-board LED ON and OFF every second for 5 times o If number entered is ODD o Turn the on-board LED ON and OFF every 0.25 second for 5 times Program runs forever You should write your own custom delayO function that uses Timer and an appropriate pre-scaler to generate one second and 0.25 second delay You have to use Output Compare approach to write your delay0 function. You may assume that the main clock frequency of the device is 16 MHz. Comment your code (.ino file) and email to your instructor by the beginning of the class (on the day the homework is due). Your instructor should be able to successfully compile your code, download your code on the board, enter input and see the LED flash accordingly

Solution

#include <stdio.h>
#include <wiringPi.h>

int main()
{
   int LED = 0;
   wiringPiSetup ();
pinMode (0, OUTPUT);
pinMode (1, INPUT);
digitalWrite (0, LOW);
int num;
printf(\"Enter an integer: \");
scanf(\"%d\", &num);

if (num & 1 == 1){
printf(\"\ Odd\");
   for(int i=0;i<5000;i++){
       if(i%1000 == 0 && i>0){
       LED = 0;
       digitalWrite(0, LOW);
       LED = 1;
       digitalWrite(1, HIGH);
       }
   }
   }
  
else
for(int i=0;i<5000;i++){
       if(i%250 == 0 && i>0){
       LED = 0;
       digitalWrite(0, LOW);
       LED = 1;
       digitalWrite(1, HIGH);
       }
   }

return 0;
}

 4. [20 pts] Write a complete C program that performs the following sequence Asks user to enter a number between 0 and 9 Identifies whether the number entered i

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site