compilation Faild - mtor speed with potentiometer

const int potPin = A0;
int portVal;
int angle;
int const motorPin = 9;

void setup() {
  
    pinMode(motorPin, OUTPUT);
}
void loop() {

    potVal = analogRead(potPin);
    Serial.print("potVal: ");
    Serial.print(potVal);
    angle = map(potVal, 0, 1023, 0, 255);
    Serial.print(", angle: ");
    Serial.println(angle);
    analogWrite(motorPin,angle);
    
    }

What's my failure? I want use a potentiometer to set motor speed... Please can you help me?

What's my failure?

Didn't the compiler tell you?

int portVal;

The program didn't compile. What have I do to make it compile? I don't know

The program didn't compile

But you didn't tell us why, so I pointed out your mistake for you.

I have this:

const int potPin = A0;
int angle;
int const motorPin = 9;

void setup() {
  
    pinMode(motorPin, OUTPUT);
}
void loop() {

    potVal = analogRead(potPin);
    Serial.print("potVal: ");
    Serial.print(potVal);
    angle = map(potVal, 0, 1023, 0, 255);
    Serial.print(", angle: ");
    Serial.println(angle);
    analogWrite(motorPin,angle);
    
    }

So... the program don't compiler and I don't know make it compiler. I need that the motor speep move with the control of the potentiometer...

You keep missing my hints, so I'm going to make it obvious; POST THE ERROR MESSAGES. They're the things that mention "potVal" and "scope" (another hint)

BTW, your original post was probably (I haven't tried compiling any of it) only one letter away from being correct - the code you posted second was much worse.

Spelling is important to compilers.

. . . and to forum moderators :D

You must post the messages that the compiler gives you.

Better still - read and try to understand them before you post. There's a fine chance that you may be able to figure this one out for yourself.

Chapter09_feb17.ino: In function ‘void loop()’:
Chapter09_feb17.ino:11:5: error: ‘potVal’ was not declared in this scope

this is the message when I compiled the program

So, you have to ask yourself, "Where is "potVal" declared?"

(Also, have another look at reply #1)

(Your IP address suggests to me that there may be people nearby who can help you answer this question)