Tutorial.Button History

Hide minor edits - Show changes to markup

December 06, 2013, at 12:16 PM by Roberto Guido -
Changed lines 31-34 from:
to:
June 01, 2010, at 03:13 PM by Equipo Traduccion -
June 01, 2010, at 03:12 PM by Equipo Traduccion -
Changed lines 19-21 from:

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

to:

imagen desarollada usando Fritzing. Para más circuitos de ejemplo, ver la página del proyecto Fritzing

June 01, 2010, at 03:10 PM by Equipo Traduccion -
Changed lines 14-15 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, it will randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resistor in the circuit.

to:

Si se desconectas el pin digital de E/S del todo, el LED puede parpadear de forma errática. Esto se debe a la entrada es "flotante", es decir, al azar se tornará en HIGH o LOW. Por eso se necesita la resistencia pull-up o pull-down en el circuito.

Changed lines 22-25 from:

Schematic:

click the image to enlarge

to:

Esquema:

haz click en la imagen para ampliar

Changed lines 28-29 from:

Code

to:

Código

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

You can also wire this circuit the opposite way, with a pullup resistor keeping the input HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button.

to:

También puedes cablear el circuito en sentido contrario, con una resistencia "pull-up" que mantenga la entrada en HIGH, y que pase a LOW cuando se pulse el botón. Así, el comportamiento del programa (sketch) se invertirá, con el LED normalmente encendido y apagado cuando se pulsa el botón.

Changed lines 16-17 from:

Circuit

to:

Circuito

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

Cuando el pulsador está abierto (desactivado) no hay conexión entre las dos patas del pulsador, de modo que el pasador está conectado a tierra (a través de la resistencia pull-down) y leemos un BAJO. Cuando el botón se cierra (presionado), se establece una conexión entre sus dos piernas, que conecta el pin a 5 voltios, por lo que leemos un ALTO. 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 5 volts, so that we read a HIGH.

to:

Cuando el pulsador está abierto (sin pulsar) no hay conexión entre las dos patas del pulsador, de forma 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 la unión entre sus dos extremos, conectando el pin a 5 voltios, por lo que leemos un HIGH (alto ó 1).

June 01, 2010, at 02:56 PM by Equipo Traduccion -
Changed lines 6-8 from:

Connect three wires to the Arduino board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply.

to:

Conecta tres cables a la placa Arduino. Los dos primeros, rojo y negro, conectan a las dos hileras largas verticales de los laterales de la placa universal (breadboard ) para proporcionar acceso a la fuente de 5 voltios y a masa (ground). El tercer cable va desde el pin digital 2 a una patilla del pulsador. Esa misma patilla del pulsador se conecta a través de una resistencia pull-down (en este caso 10 KOhms) a masa. El otro extremo del pulsador se conecta a la fuente de 5 voltios.

Cuando el pulsador está abierto (desactivado) no hay conexión entre las dos patas del pulsador, de modo que el pasador está conectado a tierra (a través de la resistencia pull-down) y leemos un BAJO. Cuando el botón se cierra (presionado), se establece una conexión entre sus dos piernas, que conecta el pin a 5 voltios, por lo que leemos un ALTO.

June 01, 2010, at 02:51 PM by Equipo Traduccion -
Changed lines 1-5 from:

Examples > Digital I/O

Button

Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button.

to:

Ejemplos > E/S (I/O) Digital

Botón

Los pulsadores o switches conectan dos puntos de un circuito al ser pulsados. Este ejemplo enciende el LED integrado en el pin 13 cuando pulsas el botón.

February 24, 2010, at 04:22 AM by Tom Igoe -
Changed lines 33-55 from:
 /*
   Button
  
  Turns on and off a light emitting diode(LED) connected to digital  
  pin 13, when pressing a pushbutton attached to pin 2. 
  
  
  The circuit:
  * LED attached from pin 13 to ground 
  * pushbutton attached to pin 2 from +5V
  * 10K resistor attached to pin 2 from ground
  
  * Note: on most Arduinos there is already an LED on the board
  attached to pin 13.
  
  
  created 2005
  by DojoDave <http://www.0j0.org>
  modified 17 Jun 2009
  by Tom Igoe
  
   http://www.arduino.cc/en/Tutorial/Button
  */
to:
Deleted lines 34-64:
 // constants won't change. They're used here to 
 // set pin numbers:
 const int buttonPin = 2;     // the number of the pushbutton pin
 const int ledPin =  13;      // the number of the LED pin

 // variables will change:
 int buttonState = 0;         // variable for reading the pushbutton status

 void setup() {
   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize the pushbutton pin as an input:
   pinMode(buttonPin, INPUT);     
 }

 void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);

   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
   if (buttonState == HIGH) {     
     // turn LED on:    
     digitalWrite(ledPin, HIGH);  
   } 
   else {
     // turn LED off:
     digitalWrite(ledPin, LOW); 
   }
 }
November 18, 2009, at 04:38 PM by David A. Mellis -
Changed line 37 from:
  pin 13, when pressing a pushbutton attached to pin 7. 
to:
  pin 13, when pressing a pushbutton attached to pin 2. 
August 27, 2009, at 08:45 PM by Tom Igoe -
Changed lines 20-22 from:

image developed using fritzing

to:

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

August 27, 2009, at 08:43 PM by Tom Igoe -
Changed lines 20-22 from:
to:

image developed using fritzing

Changed lines 28-29 from:

image developed using fritzing

to:
August 27, 2009, at 08:42 PM by Tom Igoe -
Changed lines 26-27 from:
to:

image developed using fritzing

July 05, 2009, at 07:12 PM by Tom Igoe -
Changed line 86 from:
to:
July 05, 2009, at 07:11 PM by Tom Igoe -
Changed lines 27-28 from:
 !!!Code
to:

Code

July 05, 2009, at 07:11 PM by Tom Igoe -
Added lines 27-53:
Changed lines 55-57 from:

[@ /*

  Button
to:
 // constants won't change. They're used here to 
 // set pin numbers:
 const int buttonPin = 2;     // the number of the pushbutton pin
 const int ledPin =  13;      // the number of the LED pin
Changed lines 60-61 from:
 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 2. 
to:
 // variables will change:
 int buttonState = 0;         // variable for reading the pushbutton status
Added lines 63-68:
 void setup() {
   // initialize the LED pin as an output:
   pinMode(ledPin, OUTPUT);      
   // initialize the pushbutton pin as an input:
   pinMode(buttonPin, INPUT);     
 }
Changed lines 70-73 from:
 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
to:
 void loop(){
   // read the state of the pushbutton value:
   buttonState = digitalRead(buttonPin);
Changed lines 74-75 from:
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
to:
   // check if the pushbutton is pressed.
   // if it is, the buttonState is HIGH:
   if (buttonState == HIGH) {     
     // turn LED on:    
     digitalWrite(ledPin, HIGH);  
   } 
   else {
     // turn LED off:
     digitalWrite(ledPin, LOW); 
   }
 }
Changed lines 86-125 from:
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 17 Jun 2009
 by Tom Igoe

 * http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to // set pin numbers: const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin

// variables will change: int buttonState = 0; // variable for reading the pushbutton status

void setup() {

  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     

}

void loop(){

  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }

} @]

to:
July 02, 2009, at 11:48 PM by Tom Igoe -
Changed line 33 from:
 pin 13, when pressing a pushbutton attached to pin 7. 
to:
 pin 13, when pressing a pushbutton attached to pin 2. 
Changed lines 38-39 from:
 * pushbutton attached to pin 7 from +5V
 * 10K resistor attached to pin 7 from ground
to:
 * pushbutton attached to pin 2 from +5V
 * 10K resistor attached to pin 2 from ground
Changed line 55 from:

const int buttonPin = 7; // the number of the pushbutton pin

to:

const int buttonPin = 2; // the number of the pushbutton pin

June 25, 2009, at 02:04 PM by Tom Igoe -
Changed lines 4-8 from:

The pushbutton is a component that connects two points in a circuit when you press it. The example turns on an LED when you press the button.

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

to:

Pushbuttons or switches connect two points in a circuit when you press them. This example turns on the built-in LED on pin 13 when you press the button.

Connect three wires to the Arduino board. The first two, red and black, connect to the two long vertical rows on the side of the breadboard to provide access to the 5 volt supply and ground. The third wire goes from digital pin 2 to one leg of the pushbutton. That same leg of the button connects through a pull-down resistor (here 10 KOhms) to ground. The other leg of the button connects to the 5 volt supply.

Changed lines 10-15 from:

two legs of the pushbutton, so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to ground, so that we read a LOW. (The pin is still connected to 5 volts, but the resistor in-between them means that the pin is "closer" to ground.)

You can also wire this circuit the opposite way, with a pull-down resistor keeping the input LOW, and going HIGH when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button.

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

to:

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 5 volts, so that we read a HIGH.

You can also wire this circuit the opposite way, with a pullup resistor keeping the input HIGH, and going LOW when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button.

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

June 25, 2009, at 01:56 PM by Tom Igoe -
June 25, 2009, at 01:56 PM by Tom Igoe -
Changed lines 18-20 from:

Code

to:

Schematic:

click the image to enlarge

June 24, 2009, at 10:53 PM by Tom Igoe -
Changed lines 14-15 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, it will more-or-less randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resister in the circuit.

to:

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

June 17, 2009, at 11:19 PM by Tom Igoe -
Changed lines 23-26 from:

int ledPin = 13; // choose the pin for the LED int inPin = 2; // choose the input pin (for a pushbutton) int val = 0; // variable for reading the pin status

to:

/*

  Button

 Turns on and off a light emitting diode(LED) connected to digital  
 pin 13, when pressing a pushbutton attached to pin 7. 

 The circuit:
 * LED attached from pin 13 to ground 
 * pushbutton attached to pin 7 from +5V
 * 10K resistor attached to pin 7 from ground

 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.

 created 2005
 by DojoDave <http://www.0j0.org>
 modified 17 Jun 2009
 by Tom Igoe

 * http://www.arduino.cc/en/Tutorial/Button
 */

// constants won't change. They're used here to // set pin numbers: const int buttonPin = 7; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin

// variables will change: int buttonState = 0; // variable for reading the pushbutton status

Changed lines 56-57 from:
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
to:
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);      
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);     
Changed lines 63-67 from:
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH);  // turn LED ON
to:
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {     
    // turn LED on:    
    digitalWrite(ledPin, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
November 01, 2008, at 11:31 PM by David A. Mellis -
Changed lines 7-8 from:

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

to:

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

Changed lines 18-19 from:
to:
January 17, 2008, at 04:02 PM by David A. Mellis -
Added lines 14-15:

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

June 12, 2007, at 03:56 PM by David A. Mellis - mentioning pull-down resistors (in addition to pull-up)
Added lines 12-13:

You can also wire this circuit the opposite way, with a pull-down resistor keeping the input LOW, and going HIGH when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button.

April 11, 2007, at 06:10 PM by David A. Mellis -
Deleted lines 18-26:

/* invert

 * <http://www.arduino.cc/en/Tutorial/Invert>
 *
 * turns on and off a light emitting diode(LED) connected to digital  
 * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
 * concept of Active-Low, which consists in connecting buttons using a
 * 1K to 10K pull-up resistor.
 *
 */
February 03, 2007, at 03:03 PM by David A. Mellis -
Added lines 1-45:

Examples > Digital I/O

Button

The pushbutton is a component that connects two points in a circuit when you press it. The example turns on an LED when you press the button.

We connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-up resistor (here 2.2 KOhms) to the 5 volt supply. The second goes from the corresponding leg of the pushbutton to ground. The third connects to a digital i/o pin (here pin 7) 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 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to ground, so that we read a LOW. (The pin is still connected to 5 volts, but the resistor in-between them means that the pin is "closer" to ground.)

Circuit

Code

/* invert
 * <http://www.arduino.cc/en/Tutorial/Invert>
 *
 * turns on and off a light emitting diode(LED) connected to digital  
 * pin 13, when pressing a pushbutton attached to pin 7. It illustrates the
 * concept of Active-Low, which consists in connecting buttons using a
 * 1K to 10K pull-up resistor.
 *
 */
int ledPin = 13; // choose the pin for the LED
int inPin = 2;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status

void setup() {
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val == HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, LOW);  // turn LED OFF
  } else {
    digitalWrite(ledPin, HIGH);  // turn LED ON
  }
}

Share