Skip to content

Instantly share code, notes, and snippets.

@aldrinmartoq
Last active August 13, 2021 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aldrinmartoq/1e9655f302c8f039790bf5dec02cde5b to your computer and use it in GitHub Desktop.
Save aldrinmartoq/1e9655f302c8f039790bf5dec02cde5b to your computer and use it in GitHub Desktop.
Inicio Robot Joselito
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);
}
// 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