How to code to separate strings and integers sent from bluetooth to control the servo and led. I send 'a' and 'b' for on / off led, while integer 1-90 to move servopos? This is my code where is the mistake?
#include <SoftwareSerial.h>
#include <Servo.h>
Servo servo;
int bluetoothTx = 10;
int bluetoothRx = 11;
char data = 0;
SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);
void setup()
{
pinMode(13, OUTPUT);
servo.attach(9);
//setup usb serial connection to computer
Serial.begin(9600);
bluetooth.begin(9600);
delay(100);
//setup bluetooth serial connection to android
}
void loop()
{
if(Serial.available() > 0)
{
data = Serial.read();
Serial.print(data);
if(data == 'a')
digitalWrite(13, HIGH);
else if(data == 'b')
digitalWrite(13, LOW);
if(bluetooth.available()> 0 )
{
int servopos = bluetooth.read();
int servopos1;
servopos1 = servopos + 4 ;
Serial.println(servopos);
servo.write(servopos1);
}}
}