Merge Bluetooth switch into SD card writer

‘char a’ redeclared as different kind of symbol"

Is what I get on compiling when I run the following code, my aim is to get a Bluetooth prompted high/low on pin 2 for a relay switch and this will happen in conjunction with this underlying code which takes characters from a mobile phone terminal app via bluetooth and writes them t sd card.

Any help would be greatly appreciated.

#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>

#define SW 2 // define pin 2 as control pin
const byte csSD = 4;//10;
 
File testDataFile;
SoftwareSerial ssPort(5, 7);    //(RX, TX) thats to say tx on the hco6 goes to pin 5 uno, rx on hc06 to pin7
 
const byte numChars = 255; //**** 32 default ****adjust this number for the longest data set
                          // can be up to 255.
char receivedChars[numChars];
boolean newData = false;  // true whenever new data comes in
                          // must be set to false before new data can be read
void setup()
{
   pinMode(SW, OUTPUT);
   Serial.begin(9600);
   ssPort.begin(9600);
   // Send test message to other device
   ssPort.println("Hello from Arduino");
   initSD();
   Serial.println(F("starting test data reception"));
   delay(3000);
   
}

char a; // stores incoming character from other device

void loop()
{
   recvWithStartEndMarkers();  // get new data if it is there
   if (newData == true) // got new data, save it to SD
   {
      Serial.print(F("This data just received   "));
      Serial.println(receivedChars);
      //testDataFile = SD.open("test.txt", FILE_WRITE); //appends to existing text
      testDataFile = SD.open("test.txt", O_WRITE | O_CREAT | O_TRUNC);  //replaces existing text

      if (testDataFile)
      {
         Serial.print(F("Writing to test.txt..."));
         testDataFile.println(receivedChars);
         testDataFile.close();
         Serial.println(F("done."));
      }
      else
      {
         Serial.println(F(" $$$$$ error opening test.txt $$$$"));
      }
      newData = false;  // OK ready for more data
   }
}
 
void recvWithStartEndMarkers()
{
   static boolean recvInProgress = false;
   static byte ndx = 0;
   char startMarker = '@';//'<'
   char endMarker = '

; //’>’
  char rc;

while (ssPort.available() > 0 && newData == false)
  //while (Serial.available() > 0 && newData == false)
  {
      rc = ssPort.read();
      //rc = Serial.read();

if (recvInProgress == true)
      {
        if (rc != endMarker)
        {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars)
            {
              ndx = numChars - 1;
            }
        }
        else
        {
            receivedChars[ndx] = ‘\0’; // terminate the string
            recvInProgress = false;
            ndx = 0;
            newData = true;
        }
      }
      else if (rc == startMarker)
      {
        recvInProgress = true;
      }
  }
}

void initSD()
{
  Serial.print(F(“Initializing SD card…”));
  if (!SD.begin(csSD))
  {
      Serial.println(F("############ initialization failed! ########"));
      while (1);
  }
  Serial.println(F(“initialization done.”));
}

void a()
{
  if (ssPort.available())
  // if text arrived in from BT serial…
  {
    a=(ssPort.read());
    if (a==‘1’)
    {
      digitalWrite(SW, LOW);// Turn LIGH ON
      ssPort.println(“Light on”);
    }
    if (a==‘2’)
    {
      digitalWrite(SW, HIGH);// Turn LIGHT OFF
      ssPort.println(“Light off”);
    }
    if (a==’?’)
    {
      ssPort.println(“Send ‘1’ to turn LIGHT on”);
      ssPort.println(“Send ‘2’ to turn LIGHT OFF”);
    } 
   
  }
}

(deleted)

Could you tell me which line numbers I need to alter, I,m not very good at this thanks

(deleted)

No I didnt write any of this code, I have a switch code here which works in its standalone state…

[// howto https://www.youtube.com/watch?v=-E9J9ExdZ20

/*
 * This is the Arduino code for  HC-06 Bluetooth module
 * to measure the distance using arduino for robotoic car and other applications
 * Watch the video https://youtu.be/-E9J9ExdZ20
 *  * 
 * Written by Ahmad Nejrabi for Robojax Video
 * Date: Jan 01, 2018, in Ajax, Ontario, Canada
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purpose only.
 * 
 */

// original source code: https://github.com/tronixlabsAU/HC06
#include <SoftwareSerial.h>

SoftwareSerial ssPort(5, 7); 
// creates a "virtual" serial port/UART
// connect BT module TX to D10
// connect BT module RX to D11
// connect BT Vcc to 5V, GND to GND

#define SW 2 // define pin 2 as control pin

void setup()  
{
    
  // set digital pin to control as an output
  pinMode(SW, OUTPUT);

  // set the data rate for the SoftwareSerial port
  ssPort.begin(9600);

  // Send test message to other device
  ssPort.println("Hello from Arduino");
}

char a; // stores incoming character from other device

void loop() 
{
  if (ssPort.available())
  // if text arrived in from BT serial...
  {
    a=(ssPort.read());
    if (a=='1')
    {
      digitalWrite(SW, LOW);// Turn LIGH ON
      ssPort.println("Light on");
    }
    if (a=='2')
    {
      digitalWrite(SW, HIGH);// Turn LIGHT OFF
      ssPort.println("Light off");
    }
    if (a=='?')
    {
      ssPort.println("Send '1' to turn LIGHT on");
      ssPort.println("Send '2' to turn LIGHT OFF");
    }   
    
  }
}/code]

I also have the following bluetooth write to sd card that works in its standalone state and wish to merge the two together, I've altered the ... void a() to ....void ab() and it now compiles but the switch on arduino pin 2 isnt changing state, I,m getting "Hello from Arduino" on my android terminal app and when i enter 1 or 2 i get nothing in response, its supposed to reply to my terminal with "Turn Light On" etc

I can enter on the terminal app @TEST$ and this gives.....

Initializing SD card...initialization done.
starting test data reception
This data just received   sdf
Writing to test.txt...done.

on the serial monitor so i guess there isnt any connectivity issues, what could be wrong ??? many thanks

Sorry here is the Bluetooth write to sd card sketch that works in its stand alone state and I want the switch sketch to merge with it

#include <SoftwareSerial.h>
#include <SPI.h>
#include <SD.h>
 
const byte csSD = 4;//10;
 
File testDataFile;
SoftwareSerial ssPort(5, 7);    //(RX, TX) thats to say tx on the hco6 goes to pin 5 uno, rx on hc06 to pin7
 
const byte numChars = 255; //**** 32 default ****adjust this number for the longest data set
                          // can be up to 255.
char receivedChars[numChars];
boolean newData = false;  // true whenever new data comes in
                          // must be set to false before new data can be read
void setup()
{
   Serial.begin(9600);
   ssPort.begin(9600);
   initSD();
   Serial.println(F("starting test data reception"));
   delay(3000);
}
 
void loop()
{
   recvWithStartEndMarkers();  // get new data if it is there
   if (newData == true) // got new data, save it to SD
   {
      Serial.print(F("This data just received   "));
      Serial.println(receivedChars);
      //testDataFile = SD.open("test.txt", FILE_WRITE); //appends to existing text
      testDataFile = SD.open("test.txt", O_WRITE | O_CREAT | O_TRUNC);  //replaces existing text

      if (testDataFile)
      {
         Serial.print(F("Writing to test.txt..."));
         testDataFile.println(receivedChars);
         testDataFile.close();
         Serial.println(F("done."));
      }
      else
      {
         Serial.println(F(" $$$$$ error opening test.txt $$$$"));
      }
      newData = false;  // OK ready for more data
   }
}
 
void recvWithStartEndMarkers()
{
   static boolean recvInProgress = false;
   static byte ndx = 0;
   char startMarker = '@';//'<'
   char endMarker = '

; //’>’
  char rc;

while (ssPort.available() > 0 && newData == false)
  //while (Serial.available() > 0 && newData == false)
  {
      rc = ssPort.read();
     //rc = Serial.read();

if (recvInProgress == true)
     {
        if (rc != endMarker)
        {
           receivedChars[ndx] = rc;
           ndx++;
           if (ndx >= numChars)
           {
              ndx = numChars - 1;
           }
        }
        else
        {
           receivedChars[ndx] = ‘\0’; // terminate the string
           recvInProgress = false;
           ndx = 0;
           newData = true;
        }
     }
     else if (rc == startMarker)
     {
        recvInProgress = true;
     }
  }
}

void initSD()
{
  Serial.print(F(“Initializing SD card…”));
  if (!SD.begin(csSD))
  {
     Serial.println(F("############ initialization failed! ########"));
     while (1);
  }
  Serial.println(F(“initialization done.”));
}