Arduino uno interrupt timer bluetooth

I want to light 1 led on arduino uno for a certain period of time and it will end itself at the end of the time, but I want to turn it off before the time runs out. i do this with bluetooth

Hello Mehmetallicaz
Post your sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.

So it will neither be using "delay()" nor interrupts. :grin:

It is a code that we can turn on the LED within the loop for a certain period of time with the information received via Bluetooth, and turn it off at the end of the time, or turn it off before the time runs out with the information coming from Bluetooth.

[image]

Which code ?
Did you post the current sketch to see how we can help, didn´t you?
My crystalball is currently in the dishwasher.

char Incoming_value = 0;
int bkl = 5000;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
cli();
// Timer1 kesmesi ayarlanıyor
TCNT1 = 0;
TCCR1A = 0;
TCCR1B = 0;
OCR1A = 260; // 1 milisaniye çalışması için gerekli zaman kesmesi frekansı
TCCR1B |= (1 << WGM12);
TCCR1B |= (1 << CS12) | (1 << CS10);
TIMSK1 |= (1 << OCIE1A);
sei();
}

ISR(TIMER1_COMPA_vect){ //Her kesmeye girildiğinde otomatik çalıştırılacak fonksiyon.
snroku ();
}

void loop()
{
if(Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("\n");
if(Incoming_value == '1')
{
bkl = 5000;
digitalWrite(13, HIGH);
snroku();
delay(bkl);
digitalWrite(13, LOW);
}
else if(Incoming_value == '0')
{
digitalWrite(13, LOW);
}

}

}

void snroku ()
{
if(Serial.available() > 0)
{
Incoming_value = Serial.read();
Serial.print(Incoming_value);
Serial.print("\n");

  if(Incoming_value == '0')  
  {     
     digitalWrite(13, LOW); 
     bkl = 0;
     
  }       

}
}

No need for an interrupt. Do not use delay() calls just use millis(). The following tutorials should help:

BlinkWithoutDelay

Arduino Multiple Things

Several Things at a Time

Please read the instructions! :astonished:

flashing the led with bluetooth, also making it work for 5 seconds and 10 seconds, but at the same time stopping it within these periods.

Letting the led work for 5 seconds will go off by itself at the end of the time, but I want to intervene and turn it off.

[image]

To turn on and turn off a led with the data coming from bluetooth, to make it work for as long as we want and to intervene.

[image]

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.