// C++ code
//
/*
Brazo robótico controlado por botones y
potenciometro
*/
#include <Servo.h>
int Bb1 = 0;
int BS1 = 0;
int Bb2 = 0;
int BS2 = 0;
int Bb3 = 0;
int BS3 = 0;
int Poten = 0;
int x = 0;
int y = 0;
int z = 0;
Servo servo_3;
Servo servo_5;
Servo servo_6;
Servo servo_9;
void setup()
{
pinMode(A0, INPUT);
servo_3.attach(3, 500, 2500);
servo_5.attach(5, 500, 2500);
servo_6.attach(6, 500, 2500);
servo_9.attach(9, 500, 2500);
Serial.begin(9600);
pinMode(13, INPUT);
pinMode(12, INPUT);
pinMode(11, INPUT);
pinMode(10, INPUT);
pinMode(8, INPUT);
pinMode(7, INPUT);
// Bb1 = Boton Bajada 1 --- BS1 = Boton Subida 1
Bb1 = 0;
BS1 = 0;
x = 135;
// Bb2 = Boton Bajada 2 --- BS2 = Boton Subida 2
Bb2 = 0;
BS2 = 0;
y = 90;
// Bb3 = Boton Bajada 3 --- BS3 = Boton Subida 3
Bb3 = 0;
BS3 = 0;
z = 45;
Poten = map(analogRead(A0), 0, 1023, 0, 180);
servo_3.write(z);
servo_5.write(y);
servo_6.write(x);
servo_9.write(Poten);
delay(1000); // Wait for 1000 millisecond(s)
}
void loop()
{
// Servo Base
Poten = map(analogRead(A0), 0, 1023, 0, 180);
Serial.println(Poten);
servo_9.write(Poten);
// Servo Brazo Inferior
Bb1 = digitalRead(13);
BS1 = digitalRead(12);
if (Bb1 == HIGH) {
x += -1;
servo_6.write(x);
delay(50); // Wait for 50 millisecond(s)
}
if (BS1 == HIGH) {
x += 1;
servo_6.write(x);
delay(50); // Wait for 50 millisecond(s)
}
// Servo Brazo Superior
Bb2 = digitalRead(11);
BS2 = digitalRead(10);
if (Bb2 == HIGH) {
y += -1;
servo_5.write(y);
delay(50); // Wait for 50 millisecond(s)
}
if (BS2 == HIGH) {
y += 1;
servo_5.write(y);
delay(50); // Wait for 50 millisecond(s)
}
// Servo Pinza
Bb3 = digitalRead(8);
BS3 = digitalRead(7);
if (Bb3 == HIGH) {
z += -1;
servo_3.write(z);
delay(50); // Wait for 50 millisecond(s)
}
if (BS3 == HIGH) {
z += 1;
servo_3.write(z);
delay(50); // Wait for 50 millisecond(s)
}
delay(50); // Wait for 50 millisecond(s)
}
No hay comentarios.:
Publicar un comentario