BRAZO ROBOT — Arduino Uno simulation

An interactive Arduino Uno circuit simulation you can run free in your browser on Velxio, by axeldissnewcool.

Components

Sketch code

#include <Servo.h>

// ==========================================
// SERVOS
// ==========================================
Servo servo1;  // Base giratoria
Servo servo2;  // Alcance: acercar y alejar
Servo servo3;  // Brazo: subir y bajar
Servo servo4;  // Pinza

// ==========================================
// PINES DEL JOYSTICK
// ==========================================
const int JOY_X = A0;
const int JOY_Y = A1;
const int JOY_SW = 2;

// ==========================================
// PINES DE LOS SERVOS
// ==========================================
const int SERVO1_PIN = 3;
const int SERVO2_PIN = 5;
const int SERVO3_PIN = 6;
const int SERVO4_PIN = 9;

// ==========================================
// POSICIONES INICIALES
// ==========================================
float posServo1 = 90.0;
float posServo2 = 90.0;
float posServo3 = 90.0;
float posServo4 = 30.0;

// ==========================================
// LIMITES DE MOVIMIENTO
// ==========================================
const int SERVO1_MIN = 0;
const int SERVO1_MAX = 180;

const int SERVO2_MIN = 30;
const int SERVO2_MAX = 150;

const int SERVO3_MIN = 40;
const int SERVO3_MAX = 140;

const int PINZA_CERRADA = 30;
const int PINZA_ABIERTA = 70;

// ==========================================
// VELOCIDADES: GRADOS POR SEGUNDO
// ==========================================
const float VELOCIDAD_SERVO1 = 45.0;
const float VELOCIDAD_SERVO2 = 35.0;
const float VELOCIDAD_SERVO3 = 32.0;
const float VELOCIDAD_SERVO4 = 60.0;

// ==========================================
// CONFIGURACION DEL JOYSTICK
// ==========================================
const int ZONA_MUERTA = 80;

// ==========================================
// CAMBIO DE MODO CON UN SOLO CLIC
// ==========================================
bool modo2 = false;

bool botonAnterior = HIGH;
unsigned long ultimoCambioBoton = 0;

const unsigned long ANTIRREBOTE = 50;

// ==========================================
// CONTROL DEL TIEMPO
// ==========================================
unsigned long tiempoAnterior = 0;

const unsigned long INTERVALO = 20;

// ==========================================
// CONTROL DE PINZA EN MODO 1
// ==========================================
bool pinzaAbierta = false;

// ==========================================
// CALCULAR VELOCIDAD SEGUN JOYSTICK
// ==========================================
float calcularVelocidad(int lectura, float maxVelocidad) {

  int desviacion = lectura - 512;

  if (abs(desviacion) <= ZONA_MUERTA) {
    return 0.0;
  }

  return (desviacion / 512.0) * maxVelocidad;
}

// ==========================================
// CAMBIAR ENTRE MODOS
// ==========================================
void cambiarModo() {

  modo2 = !modo2;

  if (modo2) {
    Serial.println("========================");
    Serial.println("MODO 2: ALCANCE Y PINZA");
    Serial.println("Vertical: Servo 2");
    Serial.println("Horizontal: Servo 4");
    Serial.println("Servo 1 y Servo 3 quietos");
    Serial.println("==========

More projects by axeldissnewcool