-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapeamento-joystick.ino
47 lines (38 loc) · 1006 Bytes
/
mapeamento-joystick.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <Servo.h>
#define ANGULO_INICIAL_MOTOR 90
// --- Mapeamento dos Joysticks ---
#define joystick1X A0
#define joystick1Y A1
#define joystick2X A2
#define joystick2Y A3
// --- Mapeamento dos Servos ---
Servo motorBase;
Servo motorBraco1;
Servo motorBraco2;
Servo motorGarra;
// --- Inicialização ---
void setup() {
pinMode(joystick1X, INPUT);
}
// --- Loop Infinito ---
void loop() {
int posX = analogRead(joystick1X);
posX = map(posX, 0, 1023, 0, 180);
motorBase.write(posX);
delay(100);
}
// --- Funções Auxiliares ---
// --- Mapear Pinos dos Servo Motores ---
void mapearPinosDosMotores() {
motorBase.attach(5);
motorBraco1.attach(6);
motorBraco2.attach(9);
motorGarra.attach(10); // entradas com PWM
}
// --- Inicializar Ângulos Iniciais dos Motores ---
void inicializarAngulosDosMotores() {
motorBase.write(ANGULO_INICIAL_MOTOR);
motorBraco1.write(ANGULO_INICIAL_MOTOR);
motorBraco2.write(ANGULO_INICIAL_MOTOR);
motorGarra.write(ANGULO_INICIAL_MOTOR);
}