-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArduino Program.txt
More file actions
56 lines (46 loc) · 1.21 KB
/
Arduino Program.txt
File metadata and controls
56 lines (46 loc) · 1.21 KB
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
// kept two pins free in case of any emergency like the first two pins stop working
//add servo library
#include <Servo.h>
//define our servos
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;
//define our potentiometers
int pot1 = A0;
int pot2 = A1;
int pot3 = A2;
int pot4 = A3;
//variable to read the values from the analog pin (potentiometers)
int valPot1;
int valPot2;
int valPot3;
int valPot4;
void setup()
{
//attaches our servos on pins PWM 11-10-9-6 to the servos
servo1.attach(11);
servo2.attach(10);
servo3.attach(9);
servo4.attach(6);
}
void loop()
{
//reads the value of potentiometers (value between 0 and 1023)
valPot1 = analogRead(pot1);
valPot1 = map (valPot1, 0, 1023, 0, 180); //scale it to use it with the servo (value between 0 and 180)
servo1.write(valPot1); //set the servo position according to the scaled value
delay(5);
valPot2 = analogRead(pot2);
valPot2 = map (valPot2, 0, 1023, 0, 180);
servo2.write(valPot2);
delay(5);
valPot3 = analogRead(pot3);
valPot3 = map (valPot3, 0, 1023, 0, 180);
servo3.write(valPot3);
delay(5);
valPot4 = analogRead(pot4);
valPot4 = map (valPot4, 0, 1023, 0, 180);
servo4.write(valPot4);
delay(5);
}