int pin = 5;// LED connected to PWM pin 5 int pin1 = 6; int m1 = 7; int m2 = 4; int dv = 11;// LED connected to PWM pin 11 int pulsewidth2 = 0; int pulsewidth3 = 50; int pos=0; void setup() { Serial.begin(9600); pinMode(dv, OUTPUT); } void loop() { if(Serial.available()>0){ char aChar = Serial.read(); if(aChar == '<') { pos = 0; do{ while(Serial.available() <1) ; // wait for a character aChar = Serial.read(); if(aChar >= '0' && aChar <= '9') // is ch a number? pos = pos * 10 + aChar - '0'; // yes, accumulate the value } while(aChar != '>'); analogWrite(dv, (pos-256)); pos = 0; } } if(Serial.available()>0){ int userInput=Serial.read(); if(userInput=='a') // 1 to set the LED ON with pwm { digitalWrite(m2, HIGH); analogWrite(pin, 50); } if(userInput=='b') // 2 to set the LED ON with pwm { digitalWrite(m1, HIGH); analogWrite(pin, 200); } if(userInput=='o') // 0 to set the LED Off with pwm { analogWrite(pin1, pulsewidth2); analogWrite(pin, pulsewidth2); } } }