lunes, 28 de enero de 2013

Parpadeo de un led

En la mayoría de los lenguajes de programación, el primer programa que tu escribes imprime en la pantalla del ordenador la frase "Hola Mundo". Ya que una placa Arduino no tiene una pantalla, haremos parpadear un LED.

Ejemplo 1

void setup() {              
  pinMode(13, OUTPUT);  
}
void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

Ejemplo 2
const int ledPin =  13;      // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED
long previousMillis = 0;        // will store last time LED was updated
long interval = 1000;           // interval at which to blink (milliseconds)

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

void loop()
{
  unsigned long currentMillis = millis();

  if(currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;

    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(ledPin, ledState);
  }


}

No hay comentarios:

Publicar un comentario