// Learn about the ESP32 WiFi simulation in
// https://docs.wokwi.com/guides/esp32-wifi
/*
* Date: 03/08/2023
* Title: RC BLUETOOTH CAR
* Author: Rubén Lozano
* MOD Edit: RELL9030
* References:
*
*/
/******************************************************
* LIBRERIAS
******************************************************/
#include <Stepper.h>
#include <ESP32Servo.h>
/******************************************************
* VARIABLES & DEFINES
******************************************************/
//SERVO VARIABLES
const int servoPin = 18;
Servo servo;
//MOTOR VARIABLES
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
//ULTRASONIC VARIABLES
#define PIN_TRIG 34
#define PIN_ECHO 35
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 27, 26, 25, 33);
/******************************************************
* SETUP
******************************************************/
void setup()
{
Serial.begin(115200);
pinMode(PIN_TRIG, OUTPUT);
pinMode(PIN_ECHO, INPUT);
servo.attach(servoPin, 500, 2400);
servo.write(180);
}
/******************************************************
* LOOP
******************************************************/
void loop()
{
// Start a new measurement:
digitalWrite(PIN_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(PIN_TRIG, LOW);
// Read the result:
int duration = pulseIn(PIN_ECHO, HIGH);
Serial.print("Distance in CM: ");
Serial.println(duration / 58);
Serial.print("Distance in inches: ");
Serial.println(duration / 148);
delay(1000);
}
/******************************************************
* FUNCIONES
******************************************************/