Go Down

Topic: Analog Input (Read 1 time) previous topic - next topic

Vincent19

#10
Jan 29, 2013, 06:32 am Last Edit: Jan 29, 2013, 06:35 am by Vincent19 Reason: 1
Oh..I get what you means. The arduino will be reset everytime a new sketch is uploaded. So if in previous sketch I am using analog pin as digital input/output pin, do I still need to define the analog pin to be input and digitalWrite the pin as Low if I uploaded another new sketch  ?

CrossRoads

No. After a reset, or a power loss, the sketch starts new. If  your sketch never used the pins as digital outputs, you can just use them as analog inputs.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Vincent19

#12
Jan 29, 2013, 07:01 am Last Edit: Jan 29, 2013, 07:06 am by Vincent19 Reason: 1
if your code used
pinMode(D14, OUTPUT); to D19 (the analog pins)
you must use
Code:

Code: [Select]
pinMode(D14, [b]INPUT[/b]);
digitalWrite (D14, LOW);


to make A0 thru A5 inputs for analogRead to work correctly.

Then I am confuse for this again. If the new sketch starts, so the analog pins will be back to default which is as input pins. So why should I add this anymore ? Getting real confuse now ><

CrossRoads

"If the new sketch starts, so the analog pins will be back to default which is as input pins."
Yes. Stop there. Nothing else is needed.
Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Vincent19

Okay. Noted ! If I want to use the analog pins as output pins, so I have to write
Code: [Select]
digitalWrite(A0,OUTPUT )

If I were to use it as input pins, however I do not need to define it as its default is input.

Thanks !

Go Up