- // [Project 15] - 5 Flex/Bend Sensor + 5 Servo Motor + Arduino
- #include <Servo.h>
- Servo servoMotor1;
- Servo servoMotor2;
- Servo servoMotor3;
- Servo servoMotor4;
- Servo servoMotor5;
- int servoPin1 = 2;
- int servoPin2 = 3;
- int servoPin3 = 4;
- int servoPin4 = 5;
- int servoPin5 = 6;
- void setup() {
- servoMotor1.attach(servoPin1);
- servoMotor2.attach(servoPin2);
- servoMotor3.attach(servoPin3);
- servoMotor4.attach(servoPin4);
- servoMotor5.attach(servoPin5);
- }
- void loop()
- {
- int analogValue = analogRead(A0);
- int servoAngle = map(analogValue, 550, 640, 0, 179);
- servoMotor1.write(servoAngle);
- int analogValue2 = analogRead(A1);
- int servoAngle2 = map(analogValue2, 550, 640, 0, 179);
- servoMotor2.write(servoAngle2);
- int analogValue3 = analogRead(A2);
- int servoAngle3 = map(analogValue3, 550, 640, 0, 179);
- servoMotor3.write(servoAngle3);
- int analogValue4 = analogRead(A3);
- int servoAngle4 = map(analogValue4, 550, 640, 0, 179);
- servoMotor4.write(servoAngle4);
- int analogValue5 = analogRead(A4);
- int servoAngle5 = map(analogValue5, 550, 640, 0, 179);
- servoMotor5.write(servoAngle5);
- }
复制代码
|