Jun 08

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);
}
Tagged with:



En June 8 de 2009, Jorge Iván Meza Martínez escribió acerca de Modificación del segundo sketch: The LED with button and state.
Jun 08
Sketch 'The LED with a button'

Sketch 'The LED with a button'

Descripción.

Este sketch incluye el uso de un sensor (botón de pulsación) y un actuador (LED) nos permite manipular el ambiente de acuerdo a lo percibido.

La tarjeta Arduino es capaz de notar que ha sido presionado el botón (debajo del dedo en la imagen) y esta responde encendiendo el LED.  De manera antagónica, cuando el botón es liberado, la tarjeta Arduino apaga el LED.

Implementación.

Hardware.

  • En el pin digital 13 se inserta nuevamente el LED.
  • El botón se inserta en la protoboard.
  • Una de las patas del botón va a Power-5v.
  • La otra pata va al pin 7 (entrada - lectura de datos).
  • Una resistencia une la segunda pata del botón con la tierra.

Software.

#define LED 13              // Digital PIN for the LED
#define BUTTON 7            // Digital PIN for 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()
{
  if (digitalRead(BUTTON) == HIGH)    // Button is pressed
    digitalWrite(LED, HIGH);          // Turn the LED on
  else                                // Button is NOT pressed
    digitalWrite(LED, LOW);           // Turn the LED off
}
Tagged with:



En June 8 de 2009, Jorge Iván Meza Martínez escribió acerca de El segundo sketch: The LED with button.
Jun 08
The blinking LED

The blinking LED

Descripción.

Este es tal vez el programa mas sencillo que se puede hacer con Arduino, lo utilizo para verificar el éxito del proceso de instalación recién realizado.

Este sketch enciende y apaga un led con la frecuencia proporcional a los tiempos de retardo que se especifiquen.  Estos son los pasos que realiza el algoritmo.

  1. Define al pin digital 13 como la constante LED.
  2. Convierte al pin LED como salida (escribir información).
  3. Realiza infinitamente la siguiente subrutina.
    1. Enciende el LED.
    2. Espera un segundo.
    3. Apaga el LED.
    4. Espera dos tercios de segundo.

Implementación.

Hardware.

  • Tome un LED e inserte su pata positiva (mas larga) en el pin digital número 13 y su pata negativa (mas corta) en el pin digital de tierra (GND) ubicado al lado izquierdo del pin 13.

Este paso es opcional, si no se utiliza un LED "externo", el software utilizará el LED que incluye la tarjeta Arduino para propósitos de experimentación.

Software.

#define LED 13              // The LED is on 13th digital pin

void setup()
{
  pinMode(LED, OUTPUT);    // The LED digital pin is an output
}

void loop()
{
  digitalWrite(LED, HIGH);  // Turns the LED on
  delay(1000);              // Waits for a second

  digitalWrite(LED, LOW);   // Turns the LED off
  delay(666);               // Waits for 2/3 of second
}

Despliegue.

  1. Digite el código anterior en el IDE de Arduino.
  2. Presione save para almacenar el código.  Este paso es importante, de lo contrario recibirá mensajes de error del siguiente estilo.Couldn't determine program size: NullPointerException
  3. Presione play para verificar el código y de ser posible, si no hay errores, compilarlo.
  4. Presione export para enviar el software binario al microcontrolador de la tarjeta Arduino.
  5. Observe la tarjeta Arduino, el LED deberá estar titilando según las instrucciones del código.
Tagged with:



En June 8 de 2009, Jorge Iván Meza Martínez escribió acerca de Mi primer sketch con Arduino: The blinking LED.