Go Down

#### Rob311

##### Feb 06, 2010, 02:39 am
This is more of a confirmation that i read it right, but i can use my analog inputs as digital inputs right?  i would just use pin 14-19?

Code: [Select]
`digitalRead(14); //?`

#### PaulS

#1
##### Feb 06, 2010, 03:02 am
Yes, you can use the analog pins as digital pins, by numbering them 14 - 19.

That's the proper way to read the pin. Well, except that the function returns a value that must be important, or you wouldn't have called the function, so toy probably want to store the returned value somewhere.

#### herctrap

#2
##### May 12, 2010, 11:44 pm
does this also works and for the arduino mega

is this corect?

Code: [Select]
` //********** i/o scan modes on analog inputs ********** int scan1 = (8+54) ; int scan2 = (9+54); int scan3 = (10+54); int scan4 = (11+54); int scan5 = (12+54); int scan6 = (13+54); int scan7 = (14+54); //******************** inputs as i/o for the scan mode ********************int simplescan = (0+54) ; // i/o switch for simple scannint sensorenable = (1+54) ; // i/o switch for voice scanint lightenable= (2+54) ; // i/o switch for light scanint motionenable = (3+54) ; // i/o switch for motion enable scan`

#### Rob311

#3
##### May 13, 2010, 03:30 am

You would want:

Code: [Select]
` int scan1 = digitalRead(8+54) ;`

this will give you a 1/0 in scan1 and let you know if anything is connected to port (8+54=)66.

I've never used a mega so you may want to check that whole 8+54 business.

#### jem141

#4
##### Jan 19, 2011, 05:41 pm
Quick question:
Is the below correct if i want to read a push button on analog pin (0)?
its a rough version i know, but i just want to check the important parts...

pinmode(14,input);                       // set the pin to input
int BUTTON = digitalread(14);        // read analog pin 0 as digital and set it to a variable

if (BUTTON == HIGH)                   // it shows pressed
else if (BUTTON == LOW)             // it shows not pressed

hardware layout:
5v___button____10k ohm resistor___ground
|___analog pin 0

layout done as shown in:
ww.arduino.cc/en/Tutorial/Button

Thanks

#5

#6
Thanks!

#### AWOL

#7
##### Jan 19, 2011, 06:42 pm
If BUTTON is not HIGH, there is no need to check to see if it is LOW.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

#### jem141

#8
##### Jan 19, 2011, 06:54 pm
yea i will prob use an else, but wanted to explain what both scenarios  represented.

btw wouldnt it still be yes, just with unnecessary code

Go Up