SoftwareSerial mySerial(10, 11); // RX, TX
char buf[2];
int i=0;
int data;
int ledPin = 9;
void setup() {
pinMode(ledPin, OUTPUT);
// Open serial communications and wait for port to open:
Serial.begin(57600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
mySerial.begin(9600);
}
void loop() { // run over and over
if (mySerial.available()) {
for(;i<2; ){
buf = mySerial.read();
i++;
}
i = 0;
Serial.print(buf);
data = atoi(buf);
}
analogWrite(ledPin, data/10); //To see how code behaves on LED
}