int servoPin1 = 2; // Spider Control pin for servo motor int servoPin2 = 3; // Ghost Control pin for servo motor int minPulse = 500; // Minimum servo position int maxPulse = 2500; // Maximum servo position int pulse = 0; // Amount to pulse the servo int lastPulse = 0; // the time in milliseconds of the last pulse int refreshTime = 20; // the time needed in between pulses int val = 0; // variable to store the value coming from the sensor int analogPin = 0; // select the input pin for the potentiometer int sumVal = 0; //val placeholder for average int avgVal = 0; int R2_Pin4 = 4; int R2_Pin5 = 5; void setup() { Serial.begin(9600); // use the serial port to send the values to the computer pinMode(servoPin1,OUTPUT);// Spider et servo pin as an output pin pinMode(servoPin2,OUTPUT);// Ghost pulse = minPulse; // Set the motor position value to the minimum } void loop() { val = analogRead (analogPin); // read the value from the sensor for (int i ; i <= 100 ; i++){ sumVal += val; } avgVal = sumVal/100; avgVal = val; Serial.print(val,DEC); // print the value to the serial port Serial.print(0, BYTE); // Flash line - important!!!!!!!!!!!!! pulse = (val/10)*19+500; // convert the analog value // to a range between minPulse // and maxPulse. // pulse the servo again if rhe refresh time (20 ms) have passed: //Control for Servo1 -- Bats if (millis() - lastPulse >= refreshTime) { if (val >= 10 && val <= 400){ digitalWrite(servoPin1, HIGH); // Turn the motor on delayMicroseconds(pulse); // Length of the pulse sets the motor position digitalWrite(servoPin1, LOW); // Turn the motor off lastPulse = millis(); // save the time of the last pulse } } //Control for Servo2 -- Ghost if (millis() - lastPulse >= refreshTime) { if (val >= 100 && val <= 600){ digitalWrite(servoPin2, HIGH); delayMicroseconds(pulse); // Length of the pulse sets the motor position digitalWrite(servoPin2, LOW); lastPulse = millis(); // save the time of the last pulse } } }