Skip to content

Commit 5e34a3d

Browse files
Add files via upload
1 parent c19b7b3 commit 5e34a3d

File tree

1 file changed

+132
-0
lines changed

1 file changed

+132
-0
lines changed

main.ino

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
#include <Wire.h>
2+
#include <Adafruit_PWMServoDriver.h>
3+
4+
Adafruit_PWMServoDriver pca9685 = Adafruit_PWMServoDriver();
5+
6+
#define STANDARD_y 325
7+
#define STANDARD_xA 315
8+
#define STANDARD_xB 295
9+
#define STANDARD_xC 305
10+
#define STANDARD_xD 345
11+
12+
#define SERVO_yD 12
13+
#define SERVO_yC 13
14+
#define SERVO_yB 14
15+
#define SERVO_yA 15
16+
#define SERVO_xC 4
17+
#define SERVO_xA 5
18+
#define SERVO_xB 6
19+
#define SERVO_xD 7
20+
21+
struct ServoConfig {
22+
uint8_t pin;
23+
int standard;
24+
bool increasesUp;
25+
};
26+
27+
ServoConfig servos[] = {
28+
{SERVO_yA, STANDARD_y, true},
29+
{SERVO_yB, STANDARD_y, false},
30+
{SERVO_yC, STANDARD_y, false},
31+
{SERVO_yD, STANDARD_y, true},
32+
{SERVO_xA, STANDARD_xA, true},
33+
{SERVO_xB, STANDARD_xB, false},
34+
{SERVO_xC, STANDARD_xC, true},
35+
{SERVO_xD, STANDARD_xD, false}
36+
};
37+
38+
void moveServo(uint8_t servoPin, int offset) {
39+
for (ServoConfig &s : servos) {
40+
if (s.pin == servoPin) {
41+
int target = s.increasesUp ? (s.standard + offset) : (s.standard - offset);
42+
pca9685.setPWM(servoPin, 0, target);
43+
break;
44+
}
45+
}
46+
}
47+
48+
void setup() {
49+
Serial.begin(9600);
50+
pca9685.begin();
51+
pca9685.setPWMFreq(50);
52+
delay(1000);
53+
54+
sit();
55+
delay(3000);
56+
stand();
57+
delay(3000);
58+
sit();
59+
delay(3000);
60+
stand();
61+
delay(3000);
62+
sit();
63+
delay(3000);
64+
stand();
65+
delay(1500);
66+
67+
}
68+
69+
void loop() {
70+
// walk();
71+
}
72+
73+
void sit() {
74+
for (ServoConfig &s : servos) {
75+
moveServo(s.pin, 0);
76+
}
77+
}
78+
79+
void stand() {
80+
moveServo(SERVO_yA, -120);
81+
moveServo(SERVO_yB, -120);
82+
moveServo(SERVO_yC, -120);
83+
moveServo(SERVO_yD, -120);
84+
}
85+
86+
void forward_x() {
87+
moveServo(SERVO_xA, 40);
88+
moveServo(SERVO_xB, 40);
89+
moveServo(SERVO_xC, 40);
90+
moveServo(SERVO_xD, 40);
91+
}
92+
93+
void walk(){
94+
// fase 1
95+
// B e C si abbassano mentre A e D si alzano
96+
// B e C si abbassano
97+
moveServo(SERVO_yB, -120);
98+
moveServo(SERVO_yC, -120);
99+
// forse inserire delay qua
100+
// A e D si alzano
101+
moveServo(SERVO_yA, -85);
102+
moveServo(SERVO_yD, -85);
103+
delay(250);
104+
// B e C spingono indietro mentre A e D vanno avanti
105+
// B e C spingono indietro
106+
moveServo(SERVO_xB, -50);
107+
moveServo(SERVO_xC, -50);
108+
// A e D vanno avanti
109+
moveServo(SERVO_xA, 50);
110+
moveServo(SERVO_xD, 50);
111+
delay(500);
112+
// fase 2
113+
// A e D si abbassano mentre B e C si alzano
114+
// A e D si abbassano
115+
moveServo(SERVO_yA, -120);
116+
moveServo(SERVO_yD, -120);
117+
// forse inserire delay qua
118+
// B e C si alzano
119+
moveServo(SERVO_yB, -85);
120+
moveServo(SERVO_yC, -85);
121+
delay(250);
122+
// B e C vanno avanti mentre A e D spingono indietro
123+
// A e D spingono indietro
124+
moveServo(SERVO_xA, -50);
125+
moveServo(SERVO_xD, -50);
126+
// B e C vanno avanti
127+
moveServo(SERVO_xB, 50);
128+
moveServo(SERVO_xC, 50);
129+
130+
delay(500);
131+
132+
}

0 commit comments

Comments
 (0)