msp430 usando el botón como interruptor

Estoy tratando de hacer esto ( http://www.arduino.cc/en/Tutorial/Switch ) sin usar partes externas porque pude usar el ejemplo de botón del mismo sitio con este código: http://en.textsave .org/VjL ) con mi msp430g2553 usando Energia pero no funciona, ¿alguna ayuda?

const int buttonPin = PUSH2;     // the number of the pushbutton pin
const int ledPin =  GREEN_LED;   // the number of the LED pin

int state = HIGH;      // the current state of the output pin
int reading;           // the current reading from the input pin
int previous = LOW;    // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0;         // the last time the output pin was toggled
long debounce = 200;   // the debounce time, increase if the output flickers

void setup(){
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);}

void loop(){
reading = digitalRead(ledPin);

// if the input just went from LOW and HIGH and we've waited long enough
// to ignore any noise on the circuit, toggle the output pin and remember
// the time
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH){
  state = LOW;
}
else
  state = HIGH;
  time = millis();    }

digitalWrite(ledPin, state);
previous = reading;}
¿Qué es lo que no funciona? ¿Tienes un diagrama de circuito?
¿Ya lograste que Debounce funcionara?
¿El buttonPin es doble como entrada analógica? Si es así, ¿está configurado como un puerto digital? La hoja de datos sugiere que si está configurado como analógico, la entrada digital no funcionará.
el led verde está encendido y no pasa nada cuando presiono el botón, hay algunos esquemas después de la página 18: ti.com/lit/ug/slau318d/slau318d.pdf
Probé esto: energia.nu/Tutorial_Debounce.html pero no pasa nada, si cambio pinMode (buttonPin, INPUT); como pinMode(buttonPin, INPUT_PULLUP); funciona como el ejemplo de ese botón, ni siquiera me di cuenta de que esto es lo mismo que estaba tratando de hacer.
DrRobotNinja, no tengo idea de lo que eso significa.

Respuestas (1)

Eh, lo más probable es que estés usando un Launchpad rev1.5. El pin pullup externo para el botón p1.3 no está ocupado. Como no está poblado, no hay cambio de estado estacionario. Debe habilitar el pullup interno.

en lugar de pinMode(buttonPin);usarpinMode(buttonPin, INPUT_PULLUP);

Además, está tratando de leer el pin equivocado.

en lugar de reading = digitalRead(ledPin);usarreading = digitalRead(buttonPin);

no pasa nada cuando lo cambio a pinMode(buttonPin, INPUT_PULLUP); y lectura = digitalRead(ledPin); es lo mismo en mi código.
y sí, estoy usando rev 1.5
@Cagurtay la parte de lectura está mal. Piénsalo ...
Bah... Lo siento, cambié las variables a mi kit pero accidentalmente puse salida en lugar de entrada. lectura = lectura digital (botonPin); , gracias.