Last active
August 13, 2021 20:34
-
-
Save aldrinmartoq/1e9655f302c8f039790bf5dec02cde5b to your computer and use it in GitHub Desktop.
Inicio Robot Joselito
This file contains hidden or 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
int pin_trig = 12; | |
int pin_echo = 11; | |
void distancia_setup() { | |
pinMode(pin_trig, OUTPUT); | |
pinMode(pin_echo, INPUT); | |
} | |
// retorna distancia del sensor ultrasonido | |
float distancia_leer() { | |
digitalWrite(pin_trig,LOW); | |
delayMicroseconds(10); | |
digitalWrite(pin_trig, HIGH); | |
delayMicroseconds(10); | |
digitalWrite(pin_trig, LOW); | |
float tiempo = pulseIn(pin_echo, HIGH); | |
float distancia = (0.034*tiempo)/2; | |
return distancia; | |
} | |
void distancia_mostrar() { | |
float distancia = distancia_leer(); | |
Serial.print("distancia: "); | |
Serial.println(distancia); | |
} |
This file contains hidden or 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
// ROBOT JOSELITO | |
// | |
// 1. Avanzar mientras no encuentre un obstáculo | |
// 2. Si detecta un obstáculo, detenerse | |
// 3. Mirar para todos lados (izq, frente y derecha) | |
// 4. Decidir hacia dónde girar (izq ó derecha) | |
// 5. Ir al paso 1 | |
void setup() { | |
Serial.begin(9600); | |
distancia_setup(); | |
} | |
void loop() { | |
distancia_mostrar(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment