Go Down

Topic: Using buttons - Lilypad Development Board (Read 386 times) previous topic - next topic

Hi all,

I bought a Lilypad Development Board a few months ago and have finally dug it out today.

I've got digital and analog writing to the plain white LEDs and the RGB LED (managed to get a nice rainbow fade working).

I can't seem to get anything working with the buttons though - either the pushbutton (on pin A5) or the switch (on pin 2). I've not snapped the board apart so the default pins should still be connected.

I've tried switching LEDs on and also using the serial monitor (code for the latter pasted below).

Any ideas what I'm doing wrong?

Code: [Select]
int buttonPin = 2;
int value;

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

void loop()
{
  value = digitalRead(buttonPin);
  if (value == HIGH) {
    Serial.println("High!");
  } else {
    Serial.println("Low!");
  }
}

Runaway Pancake

I can't seem to get anything working with the buttons though - either the pushbutton (on pin A5) or the switch (on pin 2). I've not snapped the board apart so the default pins should still be connected.
Meaning:
a) Serial Monitor always == "High!"
b) Serial Monitor always == "Low!"
c) Neither a nor b


Probably looks funny, but change your setup function (pins are Input by Default, digWr. to an INPUT asserts the internal pullup) -- 
Code: [Select]
void setup ()
{
  Serial.begin(9600);
  digitalWrite(buttonPin,HIGH);
}
"Hello, I must be going..."
"You gotta fight -- for your right -- to party!"
Don't react - Read.
"Who is like unto the beast? who is able to make war with him?"

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy