jueves, 7 de abril de 2016

Coche Fantástico

Jugando con los leds

código semáforo

/*
  Parpadeo
  Se enciende un LED durante un segundo , luego se apaga durante un segundo , en repetidas ocasiones .

  Este código de ejemplo está en el dominio público .
 */

//Pin 13 tiene un LED conectado en la mayoría de las placas Arduino .
// give it a name:
int led = 13;
int ledamarillo = 12;
int ledrojo = 11;

//
la rutina de instalación se ejecuta una vez al pulsar RESET:
 () {              
  // inicializar el pin digital como salida.
  pinMode(led, OUTPUT);
pinMode(ledamarillo, OUTPUT);
pinMode(ledrojo, OUTPUT); 
}

//la rutina de bucle se ejecuta una y otra vez para siempre  () {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(10000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(10);               // wait for a second

  digitalWrite(ledamarillo, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(ledamarillo, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  
    digitalWrite(ledamarillo, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(ledamarillo, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  
     digitalWrite(ledamarillo, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(ledamarillo, LOW);    // turn the LED off by making the voltage LOW
  delay(100);       // wait for a second
 
  digitalWrite(ledrojo, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(10000);               // wait for a second
  digitalWrite(ledrojo, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}

Código del coche fantastico

/*
  CÓDIGO DEL SEMÁFORO
 */

// LED CONECTADO EN LAS PLACAS DE DE ARDUINO.
// DALE UN NOMBRE:
int led = 13;
int ledamarillo = 12;
int ledrojo = 11;

//  A CADA VARIABLE LE ASIGNAMOS UNA SALIDA
void setup() {               
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
pinMode(ledamarillo, OUTPUT);
pinMode(ledrojo, OUTPUT); 
}

// SE HACE UN BUCLE O REPETICIÓN INDEFINIDA
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second

  digitalWrite(ledamarillo, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(ledamarillo, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second
  
 
  digitalWrite(ledrojo, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(ledrojo, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second
 
    digitalWrite(ledamarillo, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(ledamarillo, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second
 


}

Video del semáforo

videodelsemaforo