-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProtese Simples.cpp
72 lines (55 loc) · 1.54 KB
/
Protese Simples.cpp
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <Servo.h>
Servo dedinho, anelar, meio, indicador, dedao;
const int dedinhoFlex = A0;
const int anelarFlex = A1;
const int meioFlex = A2;
const int indicadorFlex = A3;
const int dedaoFlex = A4;
void setup(){
dedinho.attach(13);
anelar.attach(12);
meio.attach(11);
indicador.attach(9);
dedao.attach(10);
dedinho.write(180);
anelar.write(180);
meio.write(180);
indicador.write(180);
dedao.write(180);
Serial.begin(9600);
}
void loop(){
fingerControl(dedinho, dedinhoFlex, 30, 180, 710, 900);
fingerControl(anelar, anelarFlex, 0, 180, 935, 965);
fingerControl(meio, meioFlex, 0, 180, 976, 985);
fingerControl(indicador, indicadorFlex, 30, 180, 850, 920);
fingerControl(dedao, dedaoFlex, 0, 180, 487, 500);
}
void fingerControl(Servo servo, int flex, int s_bent, int s_flat, int f_bent, int f_flat) {
int servo_pos;
int flex_pos;
flex_pos = analogRead(flex);
Serial.println(flex_pos);
servo_pos = map(flex_pos, f_bent, f_flat, s_bent, s_flat);
servo.write(servo_pos);
delay(100);
}
void testFlex(){
int val0 = analogRead(A0);
Serial.println("");
Serial.print(" A0: ");
Serial.print(val0);
int val1 = analogRead(A1);
Serial.print(" A1: ");
Serial.print(val1);
int val2 = analogRead(A2);
Serial.print(" A2: ");
Serial.print(val2);
int val3 = analogRead(A3);
Serial.print(" A3: ");
Serial.print(val3);
int val4 = analogRead(A4);
Serial.print(" A4: ");
Serial.print(val4);
delay(500);
}