-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #118 from noriflores/main
agregar apuntes noriflores
- Loading branch information
Showing
3 changed files
with
170 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Incluir librerías para trabajar con la matriz LED | ||
#include "Arduino_LED_Matrix.h" | ||
#include "globito.h" | ||
#include "animation.h" | ||
|
||
ArduinoLEDMatrix Pantalla; // Instancia del objeto | ||
|
||
enum State { | ||
STANDBY, | ||
ACTIVO | ||
}; | ||
|
||
const int ledPin = 13; | ||
|
||
// Pines para el sensor de proximidad | ||
const int pin_trig = 2; | ||
const int pin_echo = 4; | ||
int distance; | ||
|
||
// Configuración de distancias para activar el LED | ||
const int noHayNadie = 60; // Encender el LED 13 desde los 21 cm | ||
const int noHayNadie2 = 100; // Seguir encendido el LED hasta los 100 cm | ||
const int hayAlguien = 0; // Apagar el LED y comenzar la animación de la matriz desde los 0 cm | ||
const int hayAlguien2 = 20; // Seguir encendida la pantalla hasta los 20 cm | ||
// cuando no hay nadie esta prendido el led rojo y al detectar distancia se apaga | ||
|
||
State currentState = STANDBY; | ||
|
||
void setup() { | ||
Pantalla.begin(); | ||
pinMode(pin_trig, OUTPUT); | ||
pinMode(pin_echo, INPUT); | ||
pinMode(ledPin, OUTPUT); | ||
|
||
Serial.begin(115200); | ||
} | ||
|
||
void loop() { | ||
readDistance(); // Lee la distancia del sensor | ||
|
||
switch (currentState) { | ||
case STANDBY: | ||
//aqui se reproduce la animacion del globito en espera y el led se mantiene prendido | ||
Serial.println("En estado STANDBY"); | ||
|
||
if (distance >= noHayNadie && distance <= noHayNadie2) { | ||
digitalWrite(ledPin, HIGH); | ||
Pantalla.loadSequence(globito); | ||
Pantalla.play(true); | ||
currentState = STANDBY; | ||
} else { | ||
currentState = ACTIVO; | ||
} | ||
break; | ||
// en estado satndby poner que se mantiene prendido el led | ||
|
||
case ACTIVO: | ||
Serial.println("En estado ACTIVO"); | ||
|
||
if (distance >= hayAlguien && distance <= hayAlguien2) { | ||
digitalWrite(ledPin, LOW); | ||
Pantalla.loadSequence(animation); | ||
Pantalla.play(true); | ||
currentState = ACTIVO; | ||
} else { | ||
currentState = STANDBY; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
void readDistance() { | ||
digitalWrite(pin_trig, LOW); | ||
delayMicroseconds(2); | ||
digitalWrite(pin_trig, HIGH); | ||
delayMicroseconds(10); | ||
digitalWrite(pin_trig, LOW); | ||
|
||
long duration = pulseIn(pin_echo, HIGH); | ||
distance = duration * 0.0344 / 2; // Convertir a centímetros | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
//Trabajo de Sofia Abdallah, Nora Flores y Enzo León | ||
|
||
// Pines para el sensor de proximidad | ||
const int pin_trig = 2; | ||
const int pin_echo = 4; | ||
|
||
// Pines para los LEDs | ||
const int ledPin1 = 13; | ||
const int ledPin2 = 12; | ||
|
||
// Pin para el buzzer | ||
const int buzzer = 8; | ||
|
||
// Definir la variable para almacenar la distancia medida | ||
long duration; | ||
int distance; | ||
|
||
// Configuración de distancias para activar los LEDs | ||
const int minDistance1 = 0; // Encender el pin 13 a 0 cm | ||
const int maxDistance1 = 150; // Apagar el pin 13 a 30 cm | ||
const int minDistance2 = 151; // Encender el pin 12 a 30 cm | ||
const int maxDistance2 = 300; // Apagar el pin 12 a 50 cm | ||
|
||
void setup() { | ||
// Modos de los pines | ||
pinMode(pin_trig, OUTPUT); | ||
pinMode(pin_echo, INPUT); | ||
pinMode(ledPin1, OUTPUT); | ||
pinMode(ledPin2, OUTPUT); | ||
pinMode(buzzer, OUTPUT); | ||
|
||
// Se abre la consola para conocer los valores que entrega el componente | ||
Serial.begin(9600); | ||
} | ||
|
||
void loop() { | ||
// Generar un pulso en el pin trig para medir la distancia | ||
digitalWrite(pin_trig, LOW); | ||
delayMicroseconds(2); | ||
digitalWrite(pin_trig, HIGH); // Activar el pulso de salida | ||
delayMicroseconds(10); | ||
digitalWrite(pin_trig, LOW); | ||
|
||
// Leer la duración del pulso en el pin echo | ||
duration = pulseIn(pin_echo, HIGH); | ||
|
||
// Calcular la distancia en centímetros | ||
distance = duration * 0.0344 / 2; | ||
|
||
// Imprimir la distancia en el monitor serie | ||
Serial.print("Distancia: "); | ||
Serial.print(distance); | ||
Serial.println(" cm"); | ||
|
||
// Activar y desactivar los LEDs y el buzzer según la distancia | ||
if (distance >= minDistance1 && distance <= maxDistance1) { | ||
digitalWrite(ledPin1, LOW); // Apagar el pin 13 | ||
digitalWrite(ledPin2, HIGH); // Encender el pin 12 | ||
tone(buzzer, 2000); // Suena el buzzer (tono 1) | ||
|
||
} else if (distance >= minDistance2 && distance <= maxDistance2) { | ||
digitalWrite(ledPin1, HIGH); // Encender el pin 13 | ||
digitalWrite(ledPin2, LOW); // Apagar el pin 12 | ||
tone(buzzer, 1000); // Suena el buzzer (tono 2) | ||
|
||
} else { | ||
digitalWrite(ledPin1, LOW); // Apagar el pin 13 | ||
digitalWrite(ledPin2, LOW); // Apagar el pin 12 | ||
noTone(buzzer); // Apagar el buzzer | ||
|
||
} | ||
} |