Go Down

Topic: Leonardo analog pins not acting as digital pins? [Solved] (Read 509 times) previous topic - next topic

davenunez

Jan 02, 2013, 08:22 am Last Edit: Jan 02, 2013, 11:58 pm by davenunez Reason: 1
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: [Select]

//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);
}

johnwasser

On the Leonardo, A0 is pin 18, not 14.  Use the name A0 if you want your code to work on multiple platforms.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e


Go Up