I need help with school project.
I have to write a program to make the LED turn on when I'm enter an odd number and turn off when I enter an even number. The number entered can be up to 2 digits. I wrote the code but is not working can you help the code
void setup() {
// put your setup code here, to run once:
int led=13;
int value = 0;
Serial.begin(9600);
pinMode (led,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.println ("EET 439");
delay (10);
if(value == '1') ``
{
digitalWrite(led,HIGH);
Serial.println ("LED is ON");
}
if(value == '0')
{
digitalWrite(led,LOW);
Serial.println("LED is OFF");
}
}
}
// declare and initialize variables
const int Led = 13;
void setup()
{
Serial.begin(9600);
pinMode (Led, OUTPUT);
Serial.println ("EET 439");
}
void loop()
{
if (Serial.available()) // new serial characters available = ?
{
char inChar = Serial.read(); // read incoming characters
switch (inChar) // filter incoming character
{
case '0' ...'9': // is a number been received?
Serial.print("received number: ");
Serial.println(inChar);
digitalWrite (Led, inChar & 1); // mask lower bit of number - this bit indicates odd or even
break;
default:
// all other characters will be ignored
break;
}
}
}