I am making an Android-controlled LED system over Bluetooth but I need to use 4 LEDs. I have done Android app but I am not able to figure out this Arduino code. Can some please help me get this done?
char command;
String string;
boolean ledon = false;
#define led 5
void setup() {
Serial.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
if (Serial.available() > 0) {
string = "";
}
while(Serial.available() > 0) {
command = ((byte)Serial.read());
if(command == ':') {
break;
} else {
string += command;
}
delay(1);
}
if(string == "TO") {
ledOn();
ledon = true;
}
if(string =="TF") {
ledOff();
ledon = false;
Serial.println(string);
}
if ((string.toInt()>=0)&&(string.toInt()<=255)) {
if (ledon==true) {
analogWrite(led, string.toInt());
Serial.println(string);
delay(10);
}
}
}
void ledOn() {
analogWrite(led, 255);
delay(10);
}
void ledOff() {
analogWrite(led, 0);
delay(10);
}