martes, 5 de junio de 2018

Pulsador Retrasado

En esta práctica, hemos modificado el programa del pulsador. Desde un  principio, hay un led rojo que está encendido permanentemente, al pulsar el botón, hay un retraso de 5 segundos y el led rojo se apagará y en su lugar, se activará uno que es blanco, al dejar de pulsar el botón, habrá otro retraso y el programa volverá a su estado inicial.

El código se encuentra copiado al final de la entrada.



int pulsador = 1;
int led = 5;
int luz = 13; 

void setup() {

pinMode (luz, OUTPUT);
pinMode (pulsador, INPUT);
pinMode (led, OUTPUT);
digitalWrite (luz, HIGH);
digitalWrite (led,LOW);
}

void loop() {
if (digitalRead (pulsador) == HIGH){
  delay (5000);
  digitalWrite (led, HIGH);
  digitalWrite (luz, LOW);  
}
else{ 
  digitalWrite (led, LOW);
  digitalWrite (luz, HIGH); 
}
}

miércoles, 30 de mayo de 2018

Luz con pulsador

En esta práctica, hemos creado un programa que enciende una luz led cuando se pulsa un botón, hemos utilizado un par de variables (led y pulsador) para el programa. Mientras se mantenga pulsado el pulsador, la luz quedará encendida. En teoría, habría que utilizar dos protecciones en la placa base, pero no nos funciona el pulsador si añadimos una. De forma que hemos  utilizado GND para dar energía al pulsador y al led, pero parte de la energía del led la hemos extraído por el pin de los 5V.
Al final de la entrada está el código copiado.



int pulsador = 1;
int led = 5;

void setup() {

pinMode (pulsador, INPUT);
pinMode (led, OUTPUT);
digitalWrite (led,LOW);
}

void loop() {
if (digitalRead (pulsador) == LOW){
  digitalWrite (led, HIGH);  
}
else{ 
  digitalWrite (led, LOW); 
}
}

martes, 15 de mayo de 2018

Simulación de dos semáforos, peatones y vehículos.

En esta práctica, hemos avanzado nuestra simulación de un semáforo, esta vez, añadimos el semáforo de los peatones, tuvimos que escribir varios "DigitalWrite" sin "delays" de por medio para que funcionase. El código está copiado al final.




/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  for (int i=3; i<8; i++)
  pinMode(i, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  
  digitalWrite(3, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(7, HIGH);    // turn the LED off by making the voltage LOW
  delay(5000);              // wait for a second
  digitalWrite(3, LOW);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(7, LOW);    // turn the LED off by making the voltage LOW
  delay(75);              // wait for a second

  digitalWrite(5, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(6, HIGH);    // turn the LED off by making the voltage LOW
  delay(2000);              // wait for a second
  digitalWrite(5, LOW);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(6, LOW);    // turn the LED off by making the voltage LOW
  delay(0);              // wait for a second
     
  digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(6, HIGH);    // turn the LED off by making the voltage LOW
  delay(3000);              // wait for a second
  digitalWrite(4, LOW);   // turn the LED on (HIGH is the voltage level)
  digitalWrite(6, LOW);    // turn the LED off by making the voltage LOW
  delay(75);              // wait for a second  


miércoles, 2 de mayo de 2018

Coche Fantástico! A toda velocidad!

En la tercera practica, hemos hecho el efecto del coche fantastico, las luces van de un lado a otro parpadeando. Tuvimos que utilizar los pines 13, 12, 11, 10 y 9 junto al GND para que las luces encendieran correctamente. Al final del documento, esta el codigo escrito.



En este caso, hemos utilizado la forma lógicamente correcta de solucionar este ejercicio, sin embargo, hay otras formas, óptimas para llegar al mismo resultado con un menor número de órdenes. En este caso, utilizamos un bucle for para que la misma orden se repita varias veces en diferentes pines bajo la variable "i". Este proceso de bucle, se encuentra explicado al final de la entrada.


void setup() {

  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
}


void loop() {
  digitalWrite(13, HIGH);   
  delay(50);            
  digitalWrite(13, LOW);   
  delay(50);          

  digitalWrite(12, HIGH);  
  delay(50);            
  digitalWrite(12, LOW);  
  delay(50);       

  digitalWrite(11, HIGH);  
  delay(50);             
  digitalWrite(11, LOW);  
  delay(50);            

    digitalWrite(10, HIGH); 
  delay(50); 
  digitalWrite(10, LOW); 
  delay(50);      

    digitalWrite(9, HIGH);
  delay(50);          
  digitalWrite(9, LOW); 
  delay(50);           

    digitalWrite(10, HIGH); 
  delay(50);          
  digitalWrite(10, LOW);  
  delay(50);            

    digitalWrite(11, HIGH);
  delay(50);          
  digitalWrite(11, LOW);   
  delay(50);          

    digitalWrite(12, HIGH);  
  delay(50);         
  digitalWrite(12, LOW);  
  delay(50);         
}

--------------------------------------------------------------


/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */
void setup() {

  pinMode(13, OUTPUT); //Elegimos los pines que vamos a utilizar bajo la variable "i"
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
}


void loop() {                        //Abrimos el bucle principal del programa con una llave "{"

  for (int i=13; i>8; i--)       //Utilizamos el bucle for para darle el valor 13 a la variable "i",  después,                                               concretamos que el último número que se debe usar en el bucle ha de ser                                             superior a 8, o sea el 9. Al final, utilizamos la orden "i--" para ordenar que                                               el número de la variable "i" baje cada vez que el bucle se reinicie.
 {                                             //Además, abrimos el bucle con "{".
  digitalWrite(i, HIGH);  // En lugar de escribir un número en el pin, ponemos la variable "i".
  delay(100);       
  digitalWrite(i, LOW);
  delay(100);       

  }

   for (int i=10; i<12; i++)       //Utilizamos el bucle for para darle el valor 13 a la variable "i",  después,                                               concretamos que el último número que se debe usar en el bucle ha de ser                                             superior a 8, o sea el 9. Al final, utilizamos la orden "i--" para ordenar que                                               el número de la variable "i" baje cada vez que el bucle se reinicie.
 {                                             //Además, abrimos el bucle con "{".
  digitalWrite(i, HIGH);  // En lugar de escribir un número en el pin, ponemos la variable "i".
  delay(100);       
  digitalWrite(i, LOW);
  delay(100); 
 }}  

martes, 24 de abril de 2018

Simulación de un Semáforo, Luz verde!

Nuestro segundo proyecto, ha sido crear un semáforo, con tres luces LED (rojo, amarillo y verde). Para ello, hemos utilizado varios cables para extender la energía de GND y de los Pines. (Al final de la entrada, se encuentra el código escrito)



/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  
}

// the loop function runs over and over again forever
void loop() {
  
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(7000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(75);              // wait for a second

    digitalWrite(11, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(5000);              // wait for a second
  digitalWrite(11, LOW);    // turn the LED off by making the voltage LOW
  delay(75);              // wait for a second
  
  digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(2000);              // wait for a second
  digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW
  delay(75);              // wait for a second
  
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(3000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(75);              // wait for a second

}

lunes, 23 de abril de 2018

Parpadeo LED PIN 13

En esta primera práctica, hemos creado una luz LED que parpadea cada x tiempo.
El pin 13, tiene una característica especial, tiene al lado el pin ground (GND), de forma que, a demás de que el pin de la placa parpadee, también lo hace el LED que se ponga en el pin 13 y en GND. (Al final del documento se encuentra el código de ambos programas)



En este vídeo, se ve que ambos LEDs, se encienden a la vez a una velocidad alta, esto se debe a que hemos puesto en velocidad de delay 150, si hubiese sido más alta, habrían ido más lentos.


En este otro vídeo, solamente enciende el led integrado en la placa, a una velocidad aún mayor, la velocidad escrita en el delay es de 75.


/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(150);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(150);              // wait for a second
}

-----------------------------

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */


// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(75);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(75);              // wait for a second
}

Pulsador Retrasado

En esta práctica, hemos modificado el programa del pulsador. Desde un  principio, hay un led rojo que está encendido permanentemente, al pu...