I have been trying to control RGB strip through an app using arduino (uno) and HC-05 bluetooth module. The app sends data in the form of FFFFFF.
I have tried storing the incoming bit into char and storing it in an array. But the char is storing all the incoming bits.
This is the sample code
#include <SoftwareSerial.h>
const int red = A0;
const int green = A1;
const int blue = A2;
char input[6];
int i = 0;
SoftwareSerial BTSerial(10, 11); // RX | TX
void setup()
{
Serial.begin(9600);
//Serial.println('Enter commands:');
BTSerial.begin(38400); // HC-05 default speed in AT command more
}
void loop()
{
// Keep reading from HC-05 and send to Arduino Serial Monitor
if (BTSerial.available()){
if(BTSerial.available() && (i < 6)){
char ch = (char)BTSerial.read();
input[i] = ch;
i++;
}
Serial.print(input[0]);
}
}
Instead of getting only the first character I'm getting the entire string
FFFFFF
where as input[1] shows empty.
I have tried to split up this string in many ways but to no avail.
Can someone please tell me why this is happening and how to rectify this?