/* Multple Serial test Receives from the main serial port, sends to the others. Receives from serial port 1, sends to the main serial (Serial 0). This example works only with boards with more than one serial like Arduino Mega, Due, Zero etc The circuit: * Any serial device attached to Serial port 1 * Serial monitor open on Serial port 0: created 30 Dec. 2008 modified 20 May 2012 by Tom Igoe & Jed Roach modified 27 Nov 2015 by Arturo Guadalupi This example code is in the public domain. */ int count; String a; String l; int led = 13; // the PWM pin the LED is attached to int brightness = 0; void setup() { // initialize both serial ports: Serial.begin(9600); pinMode(led, OUTPUT); count=0; } void loop() { // read from port 0, send to port 1: if (Serial.available()) { //int count; a= Serial.readString(); if(a.indexOf("LED,") > -1){ l=a.substring(a.indexOf(",")+1); Serial.println(l); analogWrite(led, l.toInt()); // how bright the LED is } if (a=="Forward\n"){ delay(1000); Serial.println(("OK")); count=count+1; Serial.println(count); } else if (a=="Backward\n"){ delay(1000); Serial.println(("OK")); count=100; Serial.println(count); } } }