analogReference(EXTERNAL)

erm, i may be wrong here, being newbie and all

but referring to the analog pin as A1... doest that make it behave as a digital pin ?

shouldn't it be # int a = 1; #