As per title, I have 3 LEDs connected to an Uno. Also connected is an HC-05.
edit: forgot to add a question, my bad. Is there any glaring major issues in this code that I've overlooked? Not looking for anyone to write my code for me, just want to understand what I messed up and an idea of how to fix.
const int RED=2;
const int BLUE=4;
const int GREEN=6;
String inputString;
String buttonId;
char junk;
void setup() {
Serial.begin(9600);
pinMode(RED, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(GREEN, OUTPUT);
digitalWrite(RED,LOW);
digitalWrite(BLUE,LOW);
digitalWrite(GREEN,LOW);
}
void loop()
{
if(Serial.available()){
while(Serial.available())
{
char inChar = (char)Serial.read(); //read the input
inputString += inChar; //make a string of the characters coming on serial
}
Serial.println(inputString);
while (Serial.available() > 0)
{ junk = Serial.read() ; }
if(inputString == "r_on"){ // control red led
digitalWrite(RED, HIGH);
}else if(inputString == "r_off"){
digitalWrite(RED, LOW);
}
inputString = "";
if(inputString == "b_on"){ // control blue led
digitalWrite(BLUE, HIGH);
}else if(inputString == "b_off"){
digitalWrite(BLUE, LOW);
}
inputString = "";
if(inputString == "g_on"){ // control green led
digitalWrite(GREEN, HIGH);
}else if(inputString == "g_off"){
digitalWrite(GREEN, LOW);
}
inputString = "";
}
}
Picture of my App inventor block program in imgur link below