Tutorial.ButtonStateChange History

Hide minor edits - Show changes to markup

June 01, 2010, at 03:58 PM by Equipo Traduccion -
Changed lines 5-7 from:

Cuando se tiene un pulsador? trabajando, a menudo se requiere algún tipo de acción basado en las veces que se ha pulsado. Para ello, necesitas saber cuando el estado del botón cambia de apagado (off) a encendido (on), y contar cuántas veces se produce este cambio de estado. Esto se llama detección de cambio de estado o detección de extremos.

to:

Cuando se tiene un pulsador trabajando, a menudo se requiere algún tipo de acción basado en las veces que se ha pulsado. Para ello, necesitas saber cuando el estado del botón cambia de apagado (off) a encendido (on), y contar cuántas veces se produce este cambio de estado. Esto se llama detección de cambio de estado o detección de extremos.

June 01, 2010, at 03:56 PM by Equipo Traduccion -
Changed lines 5-7 from:

Cuando se tiene un pulsador? trabajando, a menudo se requiere algún tipo de acción basado en las veces que se ha pulsado. Para ello, necesitas saber cuando el estado del botón cambia de apagado (off) a encendido (on), y contar cuántas veces se produce este cambio de estado. Esto se llama cambio de estado de detección o detección de extremos.

to:

Cuando se tiene un pulsador? trabajando, a menudo se requiere algún tipo de acción basado en las veces que se ha pulsado. Para ello, necesitas saber cuando el estado del botón cambia de apagado (off) a encendido (on), y contar cuántas veces se produce este cambio de estado. Esto se llama detección de cambio de estado o detección de extremos.

June 01, 2010, at 03:54 PM by Equipo Traduccion -
Changed line 35 from:
to:
June 01, 2010, at 03:53 PM by Equipo Traduccion -
Changed lines 31-34 from:

The sketch also checks the button push counter's value, and if it's an even multiple of four, it turns the LED on pin 13 ON. Otherwise, it turns it off.

Code

to:

El programa comprueba también el valor del contador de pulsaciones de botón, y si es múltiplo de cuatro, pone el LED del pin 13 a ON (encendido). De lo contrario, lo apaga.

Código

June 01, 2010, at 03:50 PM by Equipo Traduccion -
Changed lines 29-30 from:

The sketch below continually reads the button's state. It then compares the button's state to its state the last time through the main loop. If the current button state is different from the last button state and the current button state is high, then the button changed from off to on. The sketch then increments a button push counter.

to:

El siguiente programa (sketch) lee constantemente el estado del botón. En cada lectura compara el estado del botón con el estado la anterior vez que fue leído en el bucle principal. Si el estado actual del botón es diferente del último estado leido y el estado actual es HIGH (alto o 1), entonces cambia de apagado (off) a encendido (on). Despues el programa incrementa un contador de pulsaciones del botón.

June 01, 2010, at 03:44 PM by Equipo Traduccion -
June 01, 2010, at 03:40 PM by Equipo Traduccion -
Changed lines 13-16 from:

If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, not connected to either voltage or ground. It will more or less randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.

Circuit

to:

Si desconectas el pin de E/S del todo, el LED puede parpadear de forma errática. Esto se debe a que la entrada es "flotante", es decir, no está conectada no a positivo ni a masa. Será mas o menos aleatorio devolviendo HIGH o LOW. Esta es la causa por la que se usa la resistencia pull-down en el circuito.

Circuito

Changed lines 18-24 from:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

Schematic:

click the image to enlarge

to:

imagen desarrollada utilizando Fritzing. Para mas circuitos de ejemplo, visita la página del proyecto Fritzing

Esquema:

haz click en la imagen para ampliar

June 01, 2010, at 03:33 PM by Equipo Traduccion -
Changed lines 11-12 from:

When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to voltage, so that we read a HIGH. (The pin is still connected to ground, but the resistor resists the flow of current, so the path of least resistance is to +5V.)

to:

Cuando el pulsador está abierto (sin pulsar) no hay conexión entre los dos extremos del pulsador, de modo que el pin está conectado a tierra (a través de la resistencia pull-down) y leemos un LOW (bajo ó 0). Cuando el botón se cierra (pulsado), se establece una conexión entre sus dos extremos, conectando el pin al voltaje, para que podamos leer un HIGH (alto ó 1). (El pin sigue conectado a tierra, pero la resistencia limita el flujo de corriente, por lo que la resistencia hacia +5V es menor)

June 01, 2010, at 03:27 PM by Equipo Traduccion -
Changed lines 8-9 from:

Connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-down resistor (here 10 KOhms) to ground. The second goes from the corresponding leg of the pushbutton to the 5 volt supply. The third connects to a digital i/o pin (here pin 2) which reads the button's state.

to:

Conecte tres cables a la placa Arduino. El primero va de una patilla del pulsador a través de una resistencia pull-down (en este caso 10 KOhms) a tierra. El segundo va desde la patilla del mismo lado del botón a la fuente de 5 voltios. El tercero se conecta al pin digital de E/S (I/O) (en este caso el pin 2), que lee el estado del botón.

June 01, 2010, at 03:23 PM by Equipo Traduccion -
Changed lines 1-7 from:

Examples > Digital I/O

Button State Change Detection (Edge Detection)

Once you've got a pushbutton working, you often want to do some action based on how many times the button is pushed. To do this, you need to know when the button changes state from off to on, and count how many times this change of state happens. This is called state change detection or edge detection.

to:

Ejemplos > E/S (I/O) Digital

Detección de Cambio de Estado de un Botón (Deteción de Extremos)

Cuando se tiene un pulsador? trabajando, a menudo se requiere algún tipo de acción basado en las veces que se ha pulsado. Para ello, necesitas saber cuando el estado del botón cambia de apagado (off) a encendido (on), y contar cuántas veces se produce este cambio de estado. Esto se llama cambio de estado de detección o detección de extremos.

February 24, 2010, at 04:21 AM by Tom Igoe -
Changed line 34 from:
to:
Changed lines 36-59 from:
 /*
   State change detection (edge detection)
  	
  Often, you don't need to know the state of a digital input all the time,
  but you just need to know when the input changes from one state to another.
  For example, you want to know when a button goes from OFF to ON.  This is called
  state change detection, or edge detection.
  
  This example shows how to detect when a button or button changes from off to on
  and on to off.
  	
  The circuit:
  * pushbutton attached to pin 2 from +5V
  * 10K resistor attached to pin 2 from ground
  * LED attached from pin 13 to ground (or use the built-in LED on
    most Arduino boards)
  
  created  27 Sep 2005
  modified 17 Jun 2009
  by Tom Igoe
  	
  http://arduino.cc/en/Tutorial/ButtonStateChange
  
  */
to:
Deleted lines 37-94:
 // this constant won't change:
 const int  buttonPin = 2;    // the pin that the pushbutton is attached to
 const int ledPin = 13;       // the pin that the LED is attached to

 // Variables will change:
 int buttonPushCounter = 0;   // counter for the number of button presses
 int buttonState = 0;         // current state of the button
 int lastButtonState = 0;     // previous state of the button

 void setup() {
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);
   // initialize serial communication:
   Serial.begin(9600);
 }

 void loop() {
   // read the pushbutton input pin:
   buttonState = digitalRead(buttonPin);

   // compare the buttonState to its previous state
   if (buttonState != lastButtonState) {
     // if the state has changed, increment the counter
     if (buttonState == HIGH) {
       // if the current state is HIGH then the button
       // wend from off to on:
       buttonPushCounter++;
       Serial.println("on");
       Serial.print("number of button pushes:  ");
       Serial.println(buttonPushCounter, DEC);
     } 
     else {
       // if the current state is LOW then the button
       // wend from on to off:
       Serial.println("off"); 
     }

     // save the current state as the last state, 
     //for next time through the loop
     lastButtonState = buttonState;
   }

   // turns on the LED every four button pushes by 
   // checking the modulo of the button push counter.
   // the modulo function gives you the remainder of 
   // the division of two numbers:
   if (buttonPushCounter % 4 == 0) {
     digitalWrite(ledPin, HIGH);
   } else {
    digitalWrite(ledPin, LOW);
   }

 }

December 30, 2009, at 05:20 PM by Tom Igoe -
Added lines 73-74:
   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);
August 27, 2009, at 08:45 PM by Tom Igoe -
Changed lines 17-19 from:
to:

image developed using Fritzing. For more circuit examples, see the Fritzing project page

July 05, 2009, at 07:18 PM by Tom Igoe -
Changed lines 31-32 from:
to:
July 05, 2009, at 07:17 PM by Tom Igoe -
Added lines 31-56:
Changed lines 58-65 from:

[@ /*

  State change detection (edge detection)

 Often, you don't need to know the state of a digital input all the time,
 but you just need to know when the input changes from one state to another.
 For example, you want to know when a button goes from OFF to ON.  This is called
 state change detection, or edge detection.
to:
 // this constant won't change:
 const int  buttonPin = 2;    // the pin that the pushbutton is attached to
 const int ledPin = 13;       // the pin that the LED is attached to
Changed lines 62-69 from:
 This example shows how to detect when a button or button changes from off to on
 and on to off.

 The circuit:
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 * LED attached from pin 13 to ground (or use the built-in resistor on
   (most Arduino boards)
to:
 // Variables will change:
 int buttonPushCounter = 0;   // counter for the number of button presses
 int buttonState = 0;         // current state of the button
 int lastButtonState = 0;     // previous state of the button
Changed lines 67-71 from:
 created  27 Sep 2005
 modified 17 Jun 2009
 by Tom Igoe

 http://arduino.cc/en/Tutorial/ButtonStateChange
to:
 void setup() {
   // initialize the button pin as a input:
   pinMode(buttonPin, INPUT);
   // initialize serial communication:
   Serial.begin(9600);
 }
Changed lines 74-130 from:
 */

// this constant won't change: const int buttonPin = 2; // the pin that the pushbutton is attached to const int ledPin = 13; // the pin that the LED is attached to

// Variables will change: int buttonPushCounter = 0; // counter for the number of button presses int buttonState = 0; // current state of the button int lastButtonState = 0; // previous state of the button

void setup() {

  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

void loop() {

  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter, DEC);
    } 
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off"); 
    }

    // save the current state as the last state, 
    //for next time through the loop
    lastButtonState = buttonState;
  }

  // turns on the LED every four button pushes by 
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of 
  // the division of two numbers:
  if (buttonPushCounter % 4 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }

} @]

to:
June 25, 2009, at 02:16 PM by Tom Igoe -
Changed lines 16-26 from:

The circuit

The schematic

Click the image to enlarge

Attach:Button_schem2.png Δ Δ

to:

Schematic:

click the image to enlarge

June 25, 2009, at 02:15 PM by Tom Igoe -
Changed lines 19-21 from:

The schematic

to:

The schematic

Click the image to enlarge

Attach:Button_schem2.png Δ Δ

June 25, 2009, at 12:57 AM by Tom Igoe -
Changed line 19 from:
to:
June 25, 2009, at 12:56 AM by Tom Igoe -
Changed line 19 from:
to:
June 25, 2009, at 12:56 AM by Tom Igoe -
Changed line 19 from:
to:
June 25, 2009, at 12:54 AM by Tom Igoe -
Changed lines 16-17 from:
to:

The circuit

The schematic

June 25, 2009, at 12:33 AM by Tom Igoe -
Deleted lines 103-111:

June 24, 2009, at 11:13 PM by Tom Igoe -
Added lines 1-113:

Examples > Digital I/O

Button State Change Detection (Edge Detection)

Once you've got a pushbutton working, you often want to do some action based on how many times the button is pushed. To do this, you need to know when the button changes state from off to on, and count how many times this change of state happens. This is called state change detection or edge detection.

Connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-down resistor (here 10 KOhms) to ground. The second goes from the corresponding leg of the pushbutton to the 5 volt supply. The third connects to a digital i/o pin (here pin 2) which reads the button's state.

When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to ground (through the pull-down resistor) and we read a LOW. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to voltage, so that we read a HIGH. (The pin is still connected to ground, but the resistor resists the flow of current, so the path of least resistance is to +5V.)

If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" - that is, not connected to either voltage or ground. It will more or less randomly return either HIGH or LOW. That's why you need a pull-down resistor in the circuit.

Circuit

The sketch below continually reads the button's state. It then compares the button's state to its state the last time through the main loop. If the current button state is different from the last button state and the current button state is high, then the button changed from off to on. The sketch then increments a button push counter.

The sketch also checks the button push counter's value, and if it's an even multiple of four, it turns the LED on pin 13 ON. Otherwise, it turns it off.

Code

/*
  State change detection (edge detection)

 Often, you don't need to know the state of a digital input all the time,
 but you just need to know when the input changes from one state to another.
 For example, you want to know when a button goes from OFF to ON.  This is called
 state change detection, or edge detection.

 This example shows how to detect when a button or button changes from off to on
 and on to off.

 The circuit:
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
 * LED attached from pin 13 to ground (or use the built-in resistor on
   (most Arduino boards)

 created  27 Sep 2005
 modified 17 Jun 2009
 by Tom Igoe

 http://arduino.cc/en/Tutorial/ButtonStateChange

 */

// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button
      // wend from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes:  ");
      Serial.println(buttonPushCounter, DEC);
    } 
    else {
      // if the current state is LOW then the button
      // wend from on to off:
      Serial.println("off"); 
    }

    // save the current state as the last state, 
    //for next time through the loop
    lastButtonState = buttonState;
  }

  // turns on the LED every four button pushes by 
  // checking the modulo of the button push counter.
  // the modulo function gives you the remainder of 
  // the division of two numbers:
  if (buttonPushCounter % 4 == 0) {
    digitalWrite(ledPin, HIGH);
  } else {
   digitalWrite(ledPin, LOW);
  }

}










Share