Asks user to enter a number between 0 and 9 Identifies wheth

.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 o Turn the on-board LED ON and OFF every second for 5 times If number entered is ODD Turn the on-board LED ON and OFF every 0.25 second for 5 times Program runs forever You should write your own custom delay0 function that uses Timer 1 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 it 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 \"math.h\"

String readString;

int n;

int count=0;

int ledPin = 13; //set pin 13 as led output

void setup(){

Serial.begin(9600);

Serial.println(\"Enter a number between 0 to 9 and press Enter\");

}

void loop{

while(Serial.available())

char C =Serial.read();

readString += C;

delay(2000)

if(readString.length()>0){

Serial.println(readString);

int n =readString.toInt(); //conver the entered number to integer alternatively you can use parse int

while (count<5){

if (n%2==0) // to check whether the number is odd or even

{

digitalWrite(ledPin,HIGH); // write led on

delay(1000)     // delay of 1 sec

count++;

}

else

{

digitalWrite(ledPin,HIGH)

delay(250)    // delay of 0.25 secs

count++   //

}

count == 0;

}

}

}   //close loop

 .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 o Tu
 .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 o Tu

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site