/* SerialEvent occurs whenever a new data comes in the hardware serial RX. This routine is run between each time loop() runs, so using delay inside loop can delay response. Multiple bytes of data may be available. */ void serialEvent() { while (Serial.available()) { // get the new byte: char inChar = (char)Serial.read(); // add it to the inputString: inputString += inChar; // if the incoming character is a newline, set a flag // so the main loop can do something about it: if (inChar == '\n') { stringComplete = true; } } } void setFromSerial (String inputString) { //remove newline inputString = inputString.substring(0, inputString.length() -1); char operation1 = inputString.charAt(0); if ( operation1 = 'E' ){ String string = ""; //Echo string like: EV means echo volume switch ( inputString.charAt(1) ) { case 'V': string = volume; break; case 'T': string = title; break; case 'A': string = artist; break; case 'a': string = album; break; case 'r': string = repeat; break; case 'z': string = shuffle; break; default: string = ""; break; } Serial.println(string); } else if ( operation1 = 'S' ){ bool success = true; switch ( inputString.charAt(1) ) { case '!'://Echo Serial.println(inputString.substring(1)); break; case 'V': volume = inputString.substring(1).toInt(); break; case 'T': title = inputString.substring(1); break; case 'A': artist = inputString.substring(1); break; case 'a': album = inputString.substring(1); break; case 'r': repeat = inputString.substring(1) != 0; break; case 'z': shuffle = inputString.substring(1) != 0; break; default: success = false; break; } Serial.println(int(success)); calcMaxTicks(); } else Serial.println(-1); }