Controlling Several LED methods via Bluetooth

I am modifying a toy car that has controlling's for all Lamps via Bluetooth . For this I am using a Uno R3 and HC-05 modules. So I wrote below sketch and Its working fine for continuous LED ON mode....

char data = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(13, OUTPUT); //Sets pin 13 for the Head / Rear lamps
  pinMode(12, OUTPUT); //Sets pin 12 for the Signal Lamps
}
void loop()
{
  if (Serial.available() > 0)
  {
    data = Serial.read();        //Read the  incoming  data and store it into variable data
    Serial.print(data);          //Print Value inside data in Serial monitor
    Serial.print("\n");          //New line
    if (data == 'a')             // Checks whether value of data is equal to a
      digitalWrite(12, HIGH);    //If value is a then Signal turns ON
    else if (data == 'b')        //  Checks  whether value of data is equal to 0
      digitalWrite(12, LOW);     //If value is b then Signal turns OFF
  }
  else if (Serial.available() > 0)
  {
    data = Serial.read();        //Read the  incoming  data and store it into variable data
    Serial.print(data);          //Print Value inside data in Serial monitor
    Serial.print("\n");          //New line
    if (data == 'c')             // Checks whether value of data is equal to c
      digitalWrite(13, HIGH);    //If value is c then Head Lamps turns ON
    else if (data == 'd')        //  Checks  whether value of data is equal to d
      digitalWrite(13, LOW);     //If value is d then Head Lamps turns OFF
  }
}

The question is , I need PIN -12 LED to blink (Line-18) as Car signal lamps...And I tried several methods to do it and failed...

did you just post an image of some text ? that does not help much...

study the example "blink without delay" (and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation of your ask).)

Thanks , I am a beginner and the forum also little bit new to me....Anyway I corrected the post.

thanks for keep the forum tidy :slight_smile:

have you look at the example I mentioned:

this code should always be there and then you just keep your if tests in case you receive serial commands

there is no need to read twice the Serial line, you should perform all the tests (against a,b,c,d) in the first part. if c and d should activate/deactivate the blinking you will need to keep a separate variable that will remember if you are blinking or not and use that in the blinking part of the code

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