Ok i will post all code
when i try do my code it not working and LED do not Response , if some one can send me maybe tutorial or help me to fix my code it wil happy for this
when i just do char 'i' to on and 'h' to off it work but when i try to do sting and with out delay nothing work and LED not Response
const long connectionSpeed = 9600;
const int readingLed = 6;
const int instructionLed = 7; // SET_BOTTOM_LED_ON . LED ON .SET_BOTTOM_LED_OFF
const int stringDelay = 5; // Variabele die
int incomingByte = 0; // byte
boolean readingInput = false; // Boolean
String instruction = ""; // string holder
void setup(){
Serial.begin(connectionSpeed);
Serial.flush();
pinMode(buttonPin, INPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(10, INPUT);
digitalWrite(buttonPin, HIGH);
}
void loop(){
if(calculateDelay(stringDelay, stringMillis)){
talkSerial();
}
void talkSerial(){
Serial.println("Instruction: " + instruction);
if (Serial.available() > 0) {
incomingByte = Serial.read();
switch(incomingByte){
case 35:
openInstruction();
break;
case 37:
executeInstruction();
break;
default:
addToInstruction(incomingByte);
break;
}
digitalWrite(instructionLed, HIGH);
}else{
digitalWrite(instructionLed, LOW);
}
// to add char together
void addToInstruction(int incomingByte){
if(readingInput){
char receivedCharacter = (char) incomingByte;
instruction += receivedCharacter;
}
}
// functie make the string empty
void openInstruction(){
readingInput = true;
instruction = "";
}
// take action
void executeInstruction(){
readingInput = false;
if (instruction == "SET_BOTTOM_LED_ON"){
digitalWrite(readingLed, HIGH);
}
else if (instruction == "SET_BOTTOM_LED_OFF"){
digitalWrite(readingLed, LOW);
}