Analog sketch

I am a begineer. When we are giving input through analog device i.e. variable resistor why it is not necessary to write pinMode(button,INPUT) inside the setup function in following sketch? can someone help me please.

int led = 13;
int button = A4;
int sensorvalue = 0;

void setup(){
pinmode( led , output );
}

void loop(){
sensorvalue = analogRead(button);
digitalWrite( led , HIGH );
delay(sensorvalue);
digitalWrite( led , LOW );
delay(sensorvalue);

}

why it is not necessary to write pinMode(button,INPUT) inside the setup function in following sketch?

Because pins default to being inputs when the Arduino is started. Note, however, that for digital pins you may want to set the mode to INPUT_PULLUP which must be done explicitly.

why it is not necessary to write pinMode(button,INPUT) inside the setup function in following sketch?

Because analog pins are input only.

Sorry, aarg, wrong answer.

PaulS:
Because analog pins are input only.

Seems to me I once used them for output. :slight_smile:

There must be a glitch in the forum software. I never actually posted until now. I started to, and then left the page.

aarg:
Seems to me I once used them for output. :slight_smile:

There must be a glitch in the forum software. I never actually posted until now. I started to, and then left the page.

The glitch is on my end. I meant to address that comment to UKHeliBob.

I would imagine that the analogRead() function takes care of all the required details.
Though I've never read the source.

PaulS:
The glitch is on my end. I meant to address that comment to UKHeliBob.

Whilst your answer

Because analog pins are input only.

is correct, I would contend that so was mine

Because pins default to being inputs when the Arduino is started

The two answers are not contradictory.