Created
July 21, 2021 23:11
-
-
Save ThomRoman/d2a41c4e0fc0bb48d312b37549342885 to your computer and use it in GitHub Desktop.
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
#include <LiquidCrystal.h> | |
#define ECHO 10 //Pin digital 10 para el Echo del sensor | |
#define TRIG 9 //Pin digital 9 para el Trigger del sensor | |
double tiempo = 0; | |
double distancia = 0; // | |
LiquidCrystal lcd(12,11,5,4,3,2); | |
void setup() { | |
pinMode(TRIG, OUTPUT); //pin como salida | |
pinMode(ECHO, INPUT); //pin como entrada | |
Serial.begin(9600); //iniciailzamos la comunicación | |
lcd.begin(16, 2); | |
digitalWrite(TRIG, LOW); //Inicializamos el pin con 0 | |
} | |
void loop() { | |
digitalWrite(TRIG, HIGH); | |
delayMicroseconds(10); //Enviamos un pulso de 10us | |
digitalWrite(TRIG, LOW); | |
tiempo = pulseIn(ECHO,HIGH);//obtenemos el ancho del pulso | |
distancia = tiempo/59; //escalamos el tiempo a una distancia en cm | |
if(distancia<20){ | |
lcd.setCursor(2,0); | |
lcd.print("ROMAN A. THOM"); | |
lcd.print(" probable que jale "); | |
lcd.print(" este curso "); | |
lcd.setCursor(6,1); | |
lcd.print(distancia); | |
lcd.print(" cm "); | |
lcd.scrollDisplayLeft(); | |
delay(200); | |
}else{ | |
lcd.clear(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment