int ledPin = 6;
int analogPin = 0;
int servoPin = 5;

int analogVal;
int ledVal;
int pulse = 500;

long lastPulse;
int refreshvTime = 20;

void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}

void loop(){
analogVal = analogRead(analogPin);

if (analogVal > 935){
analogWrite(ledPin, (analogVal - 935)*3.2);
pulse = ((analogVal-935) * 25) + 500;
if (pulse > 2500){
pulse = 2500;
}
}
else{
analogWrite(ledPin, analogVal);
pulse = 500;
}

if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse);
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}