Skip to content

Commit 0dd9255

Browse files
Update armdroid-class.ino
1 parent 5718e55 commit 0dd9255

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,42 @@
11
#include "armdroid.hpp"
22

3-
PartialSerialArmdroid arm(4, 7, 2, 0x012, 0x3456);
3+
uint8_t pack(uint8_t address, uint8_t data) {
4+
uint8_t revAddress = ((address & 4) >> 2) | (address & 2) | ((address & 1) << 2);
5+
return revAddress << 4 | data;
6+
}
7+
8+
PartialSerialArmdroid arm(8, 7, 3, pack);
49

510
void setup() {
11+
Serial.begin(115200);
612
pinMode(A0, INPUT);
713
pinMode(A1, INPUT);
814
pinMode(A2, INPUT);
915
pinMode(A3, INPUT);
1016
pinMode(A4, INPUT);
1117
pinMode(A5, INPUT);
18+
pinMode(13, OUTPUT);
19+
}
20+
21+
#define mmm(N, P) \
22+
r = analogRead(A##N); \
23+
if (abs(r - 512) > 50) { \
24+
arm.motorMoveby(P, map(r, 1023, 0, -20, 20)); \
25+
t += abs(r - 512); \
1226
}
1327

14-
#define mmm(N, P) r = analogRead(A##N); if (abs(r - 512) > 100) { arm.motorMoveby(P, map(r, 1023, 0, -20, 20)); t += abs(r); }
1528
void loop() {
1629
for (int i = 0; i < 20; i++) {
1730
arm.tick();
1831
delayMicroseconds(300);
1932
}
2033
int r;
21-
unsigned long t;
34+
unsigned long t = 0;
2235
mmm(0, BASE);
2336
mmm(1, SHOULDER);
2437
mmm(2, WRIST_RIGHT);
2538
mmm(3, WRIST_LEFT);
2639
mmm(4, GRIPPER);
2740
mmm(5, ELBOW);
28-
if (t == 0) arm.torqueOff();
41+
digitalWrite(13, t > 0);
2942
}

0 commit comments

Comments
 (0)