hi every one specially the memberformerlyknownasawol
my problem is i have recieve 1,1,1,1,1,* from serial port but when i want to send order like 0,0,1,0,1,* the program hangs
i have 5 keys and 5 leds
the keys worked perfectly but the leds that gets on with send order 0,0,0,0,0,* wont work
my friend make this and his leds works perfectly but mine are useless
so did u know what kind of problem may cuz that
i turn off firewall and anti virus
but i dont know what to do
plz help us
const int led1=5;
const int led2=6;
const int led3=7;
const int led4=8;
const int led5=9;
const int key1=A0;
const int key2=15;
const int key3=14;
const int key4=16;
const int key5=10;
String outputString = "";
String inputString = "";
void setup() {
// put your setup code here, to run once:
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(led5, OUTPUT);
pinMode(key1,INPUT_PULLUP);
pinMode(key2,INPUT_PULLUP);
pinMode(key3,INPUT_PULLUP);
pinMode(key4,INPUT_PULLUP);
pinMode(key5,INPUT_PULLUP);
outputString.reserve(10);
inputString.reserve(40);
Serial.begin(9600);
while (!Serial) {
;
}
}
void loop() {
// put your main code here, to run repeatedly:
outputString.concat(digitalRead(key1));
outputString.concat(",");
outputString.concat(digitalRead(key2));
outputString.concat(",");
outputString.concat(digitalRead(key3));
outputString.concat(",");
outputString.concat(digitalRead(key4));
outputString.concat(",");
outputString.concat(digitalRead(key5));
outputString.concat(",");
outputString.concat('*');
Serial.println(outputString);
outputString="";
delay(500);
}
char temp;
char inputString_index=0;
void serialEvent() {
while (Serial.available()) {
char inChar = (char)Serial.read();
inputString += inChar;
inputString_index++;
if(inChar=='*'){
temp=inputString[inputString_index-3];
if(temp=='1') digitalWrite(led5,HIGH);
else digitalWrite(led5,LOW);
temp=inputString[inputString_index-5];
if(temp=='1') digitalWrite(led4,HIGH);
else digitalWrite(led4,LOW);
temp=inputString[inputString_index-7];
if(temp=='1') digitalWrite(led3,HIGH);
else digitalWrite(led3,LOW);
temp=inputString[inputString_index-9];
if(temp=='1') digitalWrite(led2,HIGH);
else digitalWrite(led2,LOW);
temp=inputString[inputString_index-11];
if(temp=='1') digitalWrite(led1,HIGH);
else digitalWrite(led1,LOW);
inputString_index=0;
inputString="";
}
}
}