Modificación del segundo sketch: The LED with button and state

Descripción.

Este sketch se encuentra completamente basado en el anterior al cual se le modifica su funcionalidad permitiendo manipular un estado para el LED, es decir, cuando se presiona el botón el LED se enciende, aún sin necesidad de que el usuario final continúe presionandolo; este comportamiento se mantendrá hasta que el usuario presione nuevamente el botón para apagar el LED.

Ya que los cambios introducidos desde el sketch anterior corresponden a su funcionalidad, el hardware permanece sin variaciones y estas son introducidas en el software.

Implementación.

Software.

#define LED 13              // Digital PIN for the LED
#define BUTTON 7            // Digital PIN for the Button

int state = 0;              // The current state of the LED
int lastState = 0;          // The past state of the button

void setup ()
{
  pinMode(LED, OUTPUT);      // LED pin is output: turn it on/off
  pinMode(BUTTON, INPUT);    // Button pin is input: read it
}

void loop()
{
  int currentState = digitalRead(BUTTON);

  // Consider a button's change of state only when is pressed
  if (lastState == LOW && currentState == HIGH)
  {
    state = !state;

    delay(10);
  }

  lastState = currentState;

  digitalWrite(LED, state);
}
VN:F [1.8.4_1055]
Rating: 0 (from 0 votes)

Artículos relacionados:

  1. El segundo sketch: The LED with button
  2. El tercer sketch: The LED with button and fade
  3. El cuarto sketch: The LED with fotoresistor
  4. Mi primer sketch con Arduino: The blinking LED
  5. Comunicación de la tarjeta Arduino con el computador

Category: Desarrollo de hardware, Desarrollo de software | Tags: , One comment »

One Response to “Modificación del segundo sketch: The LED with button and state”

  1. El tercer sketch: The LED with button and fade | Jorge Iván Meza Martínez

    [...] sketch es la continuación del anterior, The LED with button and state, agregándole el efecto de desvanecimiento mientras se modifica la intensidad del [...]


Leave a Reply



Back to top