This wont work! Need help!

I have this code. This makes the servo spin and the led fade up and down, but the led part wont work.

int val = 0;
 


#include <Servo.h> 

Servo myservo;

void setup(){
pinMode(9, OUTPUT);

myservo.attach(8);}

void loop(){

  analogWrite(9, val);
  myservo.write(val);
  
  val = analogRead(0);            
  val = map(val, 0, 1023, 0, 70);     
       
   

delay(20);


       }

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the "Code" button above the posting area (It looks like a scroll with < > inside it).

How to use this forum

You can't use PWM on pins 9 and 10 at the same time as the Servo library because they use the same internal timer.

The Servo library supports up to 12 motors on most Arduino boards and 48 on the Arduino Mega. On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.