Se presenta el video que corresponde a la Práctica Dirigida 1, que consiste diseñar un sistema de Alarma con 3 dispositivos iniciales:
1. LED
2. Piezo o parlante
3. Botón o sensor de contacto
Durante la Práctica se va a entender como se conecta toda la circuitería y luego se realiza en la programación que simula la alarma.
Código para la programación
int pinRojo = 3; /*Variable para el LED rojo*/
int pinAzul = 5; /*Variable para el LED AZUL*/
int piezo = 6; /*Variable para el piezo*/
int boton = 2; /*Variable para el botón*/
int estado = 0;
int pinAzul = 5; /*Variable para el LED AZUL*/
int piezo = 6; /*Variable para el piezo*/
int boton = 2; /*Variable para el botón*/
int estado = 0;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(pinRojo, OUTPUT);
pinMode(pinAzul, OUTPUT);
pinMode(piezo, OUTPUT);
pinMode(boton, INPUT);
Serial.begin (9600);
}
// initialize digital pin LED_BUILTIN as an output.
pinMode(pinRojo, OUTPUT);
pinMode(pinAzul, OUTPUT);
pinMode(piezo, OUTPUT);
pinMode(boton, INPUT);
Serial.begin (9600);
}
void loop() {
while (digitalRead(boton)==0)
{
analogWrite(pinRojo, HIGH); // turn the LED on (HIGH is the voltage level)
analogWrite(pinAzul, LOW); // turn the LED off by making the voltage LOW
delay(500);
analogWrite(pinRojo, LOW); // turn the LED off by making the voltage LOW
analogWrite(pinAzul, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
tone(piezo,300,100);
Serial.println(digitalRead(boton)); // Imprime en la pantalla el valor de boton
delay(100);
}
while (digitalRead(boton)==0)
{
analogWrite(pinRojo, HIGH); // turn the LED on (HIGH is the voltage level)
analogWrite(pinAzul, LOW); // turn the LED off by making the voltage LOW
delay(500);
analogWrite(pinRojo, LOW); // turn the LED off by making the voltage LOW
analogWrite(pinAzul, HIGH); // turn the LED on (HIGH is the voltage level)
delay(100);
tone(piezo,300,100);
Serial.println(digitalRead(boton)); // Imprime en la pantalla el valor de boton
delay(100);
}
while (digitalRead(boton)==1)
{
analogWrite(pinRojo, LOW); // turn the LED on (HIGH is the voltage level)
analogWrite(pinAzul, LOW); // turn the LED off by making the voltage LOW
Serial.println(digitalRead(boton));
delay(100);
}
}
{
analogWrite(pinRojo, LOW); // turn the LED on (HIGH is the voltage level)
analogWrite(pinAzul, LOW); // turn the LED off by making the voltage LOW
Serial.println(digitalRead(boton));
delay(100);
}
}







0 comentarios:
Publicar un comentario