martes, 7 de junio de 2016

Programar: "Leds En Direcciones Opuestas"

El dia de hoy la actividad se basaba en lograr algo similar, pero no igual, a la actividad del 'auto fantástico'. La diferencia es que, en lugar de iluminar en secuencia, los diodos leds partirian desde la mitad y haciéndolo en direcciones opuestas, de ida y vuelta.

Para que esto llegue a su cumbre, se necesitaba encender dos diodos leds a la vez, de cada lado, para lo cual se usaba dos salidas digitalWrite en la misma linea de la programación, siempre y cuando los diodos compartan su delay.
Después de hacer esto se iba contando los pines de la placa conectado a los leds en secuencia pero con un orden diferente.
Al termino de la primera secuencia, se debía repetir el código pero de manera inversa para que retroceda y así pueda volver a comenzar cuando la placa ejecute el programa, creando que los diodos leds vayan de manera contraria a si.



Codigo que use en el proyecto:
void setup() {
 // put your setup code here, to run once:
pinMode(11, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT+);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
}

void loop() {
 // put your main code here, to run repeatedly:
 digitalWrite(7, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
  digitalWrite(8, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
 digitalWrite(6, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
digitalWrite(9, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
digitalWrite(5, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
 digitalWrite(10, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
  digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
digitalWrite(11, HIGH);   // turn the LED on (HIGH is the voltage level)
 delay(50);    
   digitalWrite(11, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
  digitalWrite(4, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
 digitalWrite(10, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
digitalWrite(5, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
digitalWrite(9, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
 digitalWrite(6, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
  digitalWrite(8, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);              // wait for a second
digitalWrite(7, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(50);  
  digitalWrite(7, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(1000);   
  digitalWrite(8, LOW);   // turn the LED on (HIGH is the voltage level)
 delay(1000);

No hay comentarios:

Publicar un comentario