Documentos de Académico
Documentos de Profesional
Documentos de Cultura
FACULTAD DE INGENIERÍA
ESPACIO FORMATIVO:
MICROCONTROLADORES
MCE-0801
PRÁCTICA #2
ESTUDIANTES:
int Dato;
int DataPIR;
int boton1, boton2, boton3;
// 3er Paso,Funcionalida
void loop()
{
//CapturaDatos(); //Llamar a funcion para
Obtener Datos
//MadaSerial(); //Esta funcion Manda a Puerto Serial
//ControlPuertos(); //Funcion de control de Puertos
leerBotones();
Deteccion();
delay(1000);
}
void CapturaDatos()
{
Dato = analogRead(Pin_Potenciometro); //Leo el valor de
Entrada
}
void MadaSerial()
{
//Enviar Informacion mediante el Puerto serial (RS-232)
Serial.print("El valor de entrada es:");
Serial.println(Dato);
}
void ControlPuertos()
{
// Controlar Leds
if(Dato >= 0 and Dato <= 400)
{
digitalWrite(Pin_LedRojo,HIGH);
digitalWrite(Pin_LedVerde,LOW);
digitalWrite(Pin_LedAzul,LOW);
}
else if(Dato > 401 and Dato < 800)
{
digitalWrite(Pin_LedRojo,LOW);
digitalWrite(Pin_LedVerde,HIGH);
digitalWrite(Pin_LedAzul,LOW);
}
else
{
digitalWrite(Pin_LedRojo,LOW);
digitalWrite(Pin_LedVerde,LOW);
digitalWrite(Pin_LedAzul,HIGH);
}
}
void leerBotones(){
boton1 = digitalRead(Pin_BotonRojo);
boton2 = digitalRead(Pin_BotonVerde);
boton3 = digitalRead(Pin_BotonAzul);
if(boton1 == HIGH){
for(int i = 1; i <= 9; i++){
if(i == 1 || i == 4 || i == 7){
for(int j = 1; j <= i; j++){
parpadear(Pin_LedRojo);
}
}
else if(i == 2 || i == 5 || i == 8){
for(int j = 1; j <= i; j++){
parpadear(Pin_LedVerde);
}
}
else if(i == 3 || i == 6 || i == 9)
{
for(int j = 1; j <= i; j++){
parpadear(Pin_LedAzul);
}
}
}
}
else if(boton2 == HIGH){
for(int i = 1; i <= 9; i++){
if(i == 1 || i == 7){
for(int j = 1; j <= i; j++){
parpadear(Pin_LedRojo);
}
}
else if(i == 3 || i == 9){
for(int j = 1; j <= i; j++){
parpadear(Pin_LedVerde);
}
}
else if(i == 5)
{
for(int j = 1; j <= i; j++){
parpadear(Pin_LedAzul);
}
}
}
}
else if(boton3 == HIGH)
{
for(int i = 1; i <= 9; i++){
if(i == 2 || i == 8){
for(int j = 1; j <= i; j++){
parpadear(Pin_LedRojo);
}
}
else if(i == 4){
for(int j = 1; j <= i; j++){
parpadear(Pin_LedVerde);
}
}
else if(i == 6)
{
for(int j = 1; j <= i; j++){
parpadear(Pin_LedAzul);
}
}
}
}
}
void Deteccion()
{
DataPIR = digitalRead(Pin_SensorPIR);
Serial.print("El Valor del PIR es: ");
Serial.println(DataPIR);
if( DataPIR == 1)
{
for(int i = 1; i <= 5; i++){
tone(Pin_Buffer, 5000);
delay(250);
noTone(Pin_Buffer);
delay(250);
}
}
else
{
noTone(Pin_Buffer);
}
}
void Parpadeo()
{
digitalWrite(Pin_LedRojo,HIGH);
delay(100);
digitalWrite(Pin_LedRojo,LOW);
delay(100);
}