1 | #include <Wire.h>
|
2 | #include <Adafruit_PWMServoDriver.h>
|
3 | int val; // initial value of input
|
4 |
|
5 | Adafruit_PWMServoDriver myServo = Adafruit_PWMServoDriver();
|
6 |
|
7 | #define SERVOMIN 150
|
8 | #define SERVOMAX 600
|
9 |
|
10 | uint8_t servonum = 0;
|
11 | uint8_t numberOfServos = 7;
|
12 |
|
13 | void setup() {
|
14 | Serial.begin(9600);
|
15 | myServo.begin();
|
16 | myServo.setPWMFreq(60);
|
17 | delay(10);
|
18 |
|
19 | myServo.setPWM(0, 0, 150); // set starting point
|
20 | myServo.setPWM(1, 0, 150);
|
21 | myServo.setPWM(2, 0, 150);
|
22 | myServo.setPWM(3, 0, 150);
|
23 | myServo.setPWM(4, 0, 150);
|
24 | myServo.setPWM(5, 0, 150);
|
25 | myServo.setPWM(6, 0, 150);
|
26 |
|
27 | }
|
28 |
|
29 | void loop() {
|
30 |
|
31 | if (Serial.available()) // if serial value is available
|
32 |
|
33 | {
|
34 | val = Serial.read();// then read the serial value
|
35 |
|
36 | if (val == '1') //if value input is equals to 1
|
37 |
|
38 | {
|
39 | myServo.setPWM(0, 0, 400);
|
40 | delay(15);//delay for the servo to get to the position
|
41 | }
|
42 |
|
43 | if (val == '2') //if value input is equals to 2
|
44 | {
|
45 | myServo.setPWM(1, 0, 400);
|
46 | delay(15);//delay for the servo to get to the position
|
47 | }
|
48 | if (val == '3') //if value input is equals to 2
|
49 | {
|
50 | myServo.setPWM(2, 0, 400);
|
51 | delay(15);//delay for the servo to get to the position
|
52 | }
|
53 | if (val == '4') //if value input is equals to 2
|
54 | {
|
55 | myServo.setPWM(3, 0, 400);
|
56 | delay(15);//delay for the servo to get to the position
|
57 | }
|
58 | if (val == '5') //if value input is equals to 2
|
59 | {
|
60 | myServo.setPWM(4, 0, 400);
|
61 | delay(15);//delay for the servo to get to the position
|
62 | }
|
63 | if (val == '6') //if value input is equals to 2
|
64 | {
|
65 | myServo.setPWM(5, 0, 400);
|
66 | delay(15);//delay for the servo to get to the position
|
67 | }
|
68 | if (val == '7') //if value input is equals to 2
|
69 | {
|
70 | myServo.setPWM(6, 0, 400);
|
71 | delay(15);//delay for the servo to get to the position
|
72 | }
|
73 |
|
74 | if (val == 'a') // zum wieder schließen!
|
75 |
|
76 | {
|
77 | myServo.setPWM(0, 0, 150);
|
78 | delay(15);//delay for the servo to get to the position
|
79 | }
|
80 |
|
81 | if (val == 's') //if value input is equals to 2
|
82 | {
|
83 | myServo.setPWM(1, 0, 150);
|
84 | delay(15);//delay for the servo to get to the position
|
85 | }
|
86 | if (val == 'd') //if value input is equals to 2
|
87 | {
|
88 | myServo.setPWM(2, 0, 150);
|
89 | delay(15);//delay for the servo to get to the position
|
90 | }
|
91 | if (val == 'f') //if value input is equals to 2
|
92 | {
|
93 | myServo.setPWM(3, 0, 150);
|
94 | delay(15);//delay for the servo to get to the position
|
95 | }
|
96 | if (val == 'g') //if value input is equals to 2
|
97 | {
|
98 | myServo.setPWM(4, 0, 150);
|
99 | delay(15);//delay for the servo to get to the position
|
100 | }
|
101 | if (val == 'h') //if value input is equals to 2
|
102 | {
|
103 | myServo.setPWM(5, 0, 150);
|
104 | delay(15);//delay for the servo to get to the position
|
105 | }
|
106 | if (val == 'j') //if value input is equals to 2
|
107 | {
|
108 | myServo.setPWM(6, 0, 150);
|
109 | delay(15);//delay for the servo to get to the position
|
110 | }
|
111 |
|
112 | }
|
113 |
|
114 | }
|