led goes off and again ON
char blueToothVal;
int fklc=0,tkl=0,tklc=0,thl=0,thlc=0;
char lastValue;
//int cnt;
void setup(){
Serial.begin(9600);
pinMode(13, OUTPUT);
// pinMode(12, OUTPUT);
// pinMode(11,OUTPUT);
cli();//stop interrupts
//set timer1 interrupt at 1Hz
TCCR1A = 0;// set entire TCCR1A register to 0
TCCR1B = 0;// same for TCCR1B
TCNT1 = 0;//initialize counter value to 0
// set compare match register for 1hz increments
OCR1A = 15624;// = (1610^6) / (11024) - 1 (must be <65536)
// turn on CTC mode
TCCR1B |= (1 << WGM12);
// Set CS12 and CS10 bits for 1024 prescaler
TCCR1B |= (1 << CS12) | (1 << CS10);
// enable timer compare interrupt
TIMSK1 |= (1 << OCIE1A);
sei();//allow interrupts
//cli();
}//end setup
ISR(TIMER1_COMPA_vect){//timer1 interrupt 1Hz toggles pin 13 (LED)
//generates pulse wave of frequency 1Hz/2 = 0.5Hz (takes two cycles for full wave- toggle high then toggle low)
//char blueToothVal;
if(Serial.available())//if there is data being recieved
{
blueToothVal=Serial.read(); //read it
}
if(blueToothVal=='a')//if value from bluetooth serial is n
{
int fk=60;//for one minute to glow led
digitalWrite(13,HIGH); //switch on LED
if (lastValue!='a')
Serial.println(F("Relay3 is on")); //print LED is on
lastValue=blueToothVal;
fklc=fklc+1;
if(fklc>=fk)
{
digitalWrite(13,LOW);
Serial.println(F("Relay3 is OFF"));
fklc=0;
tklc=0;
}
}
void loop(){
//do other things here
// digitalWrite(13,LOW);
}