Caracteristicas sobre el Roomba

  1. Hecho con Arduino

  2. Simulado por Thinkercad

  3. Escrito en c++

  4. Diseno inovador

Codigo del proyecto

body{
#Codigo hecho por mi 2021
int MA1=11;
int MA2=10;
int MB1=6;
int MB2=5;
const int pingPin = 3; // Pin 3 digital de arduino corresponde al echo
const int trigPin = 2; // Pin 2 digital de arduino corresponde al trigger
void setup() {
  pinMode(MA1, OUTPUT);
  pinMode(MA2, OUTPUT);
  pinMode(MB1, OUTPUT);
  pinMode(MB2, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(pingPin, INPUT);
}
void loop() {
  int cm = ping(pingPin); 
  if (cm >= 20){
    analogWrite(MA1, 150);
    analogWrite(MA2, 0);
    analogWrite(MB1, 200);
    analogWrite(MB2, 0);
  }
  if (cm < 20)
  {
    analogWrite(MA1, 0);
    analogWrite(MA2, 0);
    analogWrite(MB1, 0);
    analogWrite(MB2, 0);
		delay(1000);
    analogWrite(MA1, 150);
    analogWrite(MA2, 0);
    analogWrite(MB1, 0);
    analogWrite(MB2, 200);
    delay(500);
    analogWrite(MA1, 0);
    analogWrite(MA2, 0);
    analogWrite(MB1, 0);
    analogWrite(MB2, 0);
    delay(1000);
  }
  delay(50);
}
  int ping(int pingPin)
  {
    long duration, cm;
    pinMode(trigPin, OUTPUT);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(trigPin, LOW);
    pinMode(pingPin, INPUT);
    duration = pulseIn(pingPin, HIGH);
    cm = microsecondsToCentimeters(duration);
    return cm;
  }
long microsecondsToCentimeters(long microseconds)
{
  return microseconds / 29 / 2;
}