Pages: [1]   Go Down
Author Topic: Leonardo analog pins not acting as digital pins? [Solved]  (Read 385 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I got a new Leonardo, and have set up a simple button test (button with a 10k ohm resistor, as described in the Button tutorial). Works great on Pin 0, but when I move it to Pin 14 (A0 on the board), it does not work - pushing the button does nothing, and the data coming back from the pin seems either all 0 or random (if you move it to another digital pin such as 2, it works great). Here is the code I used. Am I missing something?
Code:
//change buttonPin to 14 and move the input to pin A0, and the code stops working as expected.
int buttonPin = 0;

void setup()
{
  pinMode(buttonPin, INPUT);
  Serial.begin(9600);
}

void loop()
{  
  int s = digitalRead(buttonPin);
  Serial.println(s);
  delay(10);
}
« Last Edit: January 02, 2013, 05:58:47 pm by davenunez » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 180
Posts: 8108
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

On the Leonardo, A0 is pin 18, not 14.  Use the name A0 if you want your code to work on multiple platforms.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Offline Offline
Newbie
*
Karma: 0
Posts: 3
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, changing to A0 solved it.
Logged

Pages: [1]   Go Up
Jump to: