my code stock.com

Alejandro Mascotto

Lección 05 - Uso de entradas y control de salidas
by Alejandro Mascotto

Control de estado de un Led mediante un pulsador

Snippet options

Download: Download snippet as leccion-05-uso-de-entradas-y-control-de-salidas.txt.
Copy snippet: For this you need a free my code stock.com account.
Embed code : You will find the embed code for this snippet at the end of the page, if you want to embed it into a website or a blog!

/* ============================================
          Encender LED con un pulsador
   ============================================
Oprimir un pulsador y mientras este se mantenga accionado
un LED se enciende

  ============================================
      Declara puertos de entradas y salidas
  ============================================*/

int pulsador = 12;                      // Pin donde se encuentra el pulsador, entrada
int pinLed = 13;                        // Pin donde se encuentra el LED, salida

/* ============================================
                Funcion principal
   ============================================*/

void setup(){                           // Se ejecuta cada vez que el Arduino se inicia

  pinMode(pulsador, INPUT);             // Configurar el pulsador como una entrada
  pinMode(pinLed, OUTPUT);              // Configurar el LED como una salida
}

/*============================================
      Bloque principal de programa cíclica
  ============================================*/

void loop(){                            // Esta función se mantiene ejecutando
                                        //// cuando este energizado el Arduino
                                        // Condicional para saber el estado del pulsador
  if (digitalRead(pulsador) == HIGH) {  // Si Pulsador esta oprimido
    digitalWrite(pinLed, HIGH);         // Enciende el LED
  }
  else{                                 // En caso contrario (Pulsador NO oprimido)
    digitalWrite(pinLed, LOW);          // Apaga el LED
  }
}                                       // Fin programa

Create a free my code stock.com account now.

my code stok.com is a free service, which allows you to save and manage code snippes of any kind and programming language. We provide many advantages for your daily work with code-snippets, also for your teamwork. Give it a try!

Find out more and register now

You can customize the height of iFrame-Codes as needed! You can find more infos in our API Reference for iframe Embeds.