1
2
3#include <Servo.h>
4
5Servo servo1;
6Servo servo2;
7Servo servo3;
8
9const int LED1 = 2;
10const int LED2 = 3;
11const int LED3 = 4;
12const int LED4 = 7;
13const int LED5 = 8;
14
15const int button1 = 12;
16const int button2 = 13;
17
18int button1Presses = 0;
19boolean button2Pressed = false;
20
21const int pot1 = A0;
22const int pot2 = A1;
23const int pot3 = A2;
24
25int pot1Val;
26int pot2Val;
27int pot3Val;
28int pot1Angle;
29int pot2Angle;
30int pot3Angle;
31
32int servo1PosSaves[] = {1,1,1,1,1};
33int servo2PosSaves[] = {1,1,1,1,1};
34int servo3PosSaves[] = {1,1,1,1,1};
35
36void setup() {
37 servo1.attach(5);
38 servo2.attach(6);
39 servo3.attach(9);
40
41 pinMode(LED1, OUTPUT);
42 pinMode(LED2, OUTPUT);
43 pinMode(LED3, OUTPUT);
44 pinMode(LED4, OUTPUT);
45 pinMode(LED5, OUTPUT);
46 pinMode(button1, INPUT);
47 pinMode(button2, INPUT);
48
49 Serial.begin(9600);
50}
51
52void loop() {
53
54 pot1Val = analogRead(pot1);
55 pot1Angle = map(pot1Val, 0, 1023, 0, 179);
56 pot2Val = analogRead(pot2);
57 pot2Angle = map(pot2Val, 0, 1023, 0, 179);
58 pot3Val = analogRead(pot3);
59 pot3Angle = map(pot3Val, 0, 1023, 0, 179);
60
61 servo1.write(pot1Angle);
62 servo2.write(pot2Angle);
63 servo3.write(pot3Angle);
64
65 if(digitalRead(button1) == HIGH){
66 button1Presses++;
67 switch(button1Presses){
68 case 1:
69 servo1PosSaves[0] = pot1Angle;
70 servo2PosSaves[0] = pot2Angle;
71 servo3PosSaves[0] = pot3Angle;
72 digitalWrite(LED1, HIGH);
73 Serial.println("Pos 1 Saved");
74 break;
75 case 2:
76 servo1PosSaves[1] = pot1Angle;
77 servo2PosSaves[1] = pot2Angle;
78 servo3PosSaves[1] = pot3Angle;
79 digitalWrite(LED2, HIGH);
80 Serial.println("Pos 2 Saved");
81 break;
82 case 3:
83 servo1PosSaves[2] = pot1Angle;
84 servo2PosSaves[2] = pot2Angle;
85 servo3PosSaves[2] = pot3Angle;
86 digitalWrite(LED3, HIGH);
87 Serial.println("Pos 3 Saved");
88 break;
89 case 4:
90 servo1PosSaves[3] = pot1Angle;
91 servo2PosSaves[3] = pot2Angle;
92 servo3PosSaves[3] = pot3Angle;
93 digitalWrite(LED4, HIGH);
94 Serial.println("Pos 4 Saved");
95 break;
96 case 5:
97 servo1PosSaves[4] = pot1Angle;
98 servo2PosSaves[4] = pot2Angle;
99 servo3PosSaves[4] = pot3Angle;
100 digitalWrite(LED5, HIGH);
101 Serial.println("Pos 5 Saved");
102 break;
103 }
104 }
105
106 if(digitalRead(button2) == HIGH){
107 button2Pressed = true;
108 }
109
110 if(button2Pressed){
111 for(int i = 0; i < 5; i++){
112 servo1.write(servo1PosSaves[i]);
113 servo2.write(servo2PosSaves[i]);
114 servo3.write(servo3PosSaves[i]);
115 Serial.println(" potentimeter Angles: ");
116 Serial.println(servo1PosSaves[i]);
117 Serial.println(servo2PosSaves[i]);
118 Serial.println(servo3PosSaves[i]);
119 delay(1050);
120 }
121 }
122 delay(300);
123}