Pages: [1]   Go Down
Author Topic: Analog input as digital input for button  (Read 16619 times)
0 Members and 1 Guest are viewing this topic.
Queens, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks =op
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
digitalRead(14); //?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 610
Posts: 49077
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 146
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

does this also works and for the arduino mega

is this corect?

Code:
//********** 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 scann
int sensorenable = (1+54) ; // i/o switch for voice scan
int lightenable= (2+54) ; // i/o switch for light scan
int motionenable = (3+54) ; // i/o switch for motion enable scan
Logged

Queens, NY
Offline Offline
Jr. Member
**
Karma: 0
Posts: 57
Arduino rocks =op
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You aren't reading the pin.

You would want:

Code:
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.

Logged

Pittsburgh PA
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley
Logged

Hyderabad , India
Offline Offline
God Member
*****
Karma: 6
Posts: 621
can't help not to think arduinaizing something !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quick reply Yes!
Logged

Pittsburgh PA
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks!
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 300
Posts: 26219
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Slower reply, no.
If BUTTON is not HIGH, there is no need to check to see if it is LOW.
Logged

"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.

Pittsburgh PA
Offline Offline
Newbie
*
Karma: 0
Posts: 3
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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  smiley-razz
Logged

Pages: [1]   Go Up
Jump to: