'analogPin' was not declared in this scope

So this is my script and it has an error but i can not figure it out I need some help.

int ledPin = 13;


long onTime = 250;


int minDelay = 100;


int maxDelay = 100;



long strobeDelay = 0;

void setup() {
 pinMode(ledPin, OUTPUT);
}

void loop() {

  strobeDelay = map(analogRead(analogPin), 0, 1023, minDelay, maxDelay);

  digitalWrite(ledPin, HIGH);
  delayMicroseconds(onTime);
  digitalWrite(ledPin, LOW);
  delay(strobeDelay);
}

The error message is quite right :wink: you haven't a pin called analogPin. Either change the read to analogRead(0) (or whatever its number is), or add a line at the top:

byte analogPin=0; //or whatever number

1 Like

Thank you very much

The analogRead() function is smart enough to differentiate between digital pin 0 and analog channel 0 when you use analogRead(0);, but it makes the code more readable if you use the Ax notation when specifying the analog input pins,

analogRead(A0);

Or

const byte analogPin = A0;
int input = analogRead(analogPin);

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.