// B_PM01_ServosMid // set servos to mid position so servo horns can be fitted in the correct orientation // servo pulse at mid position =1500 micro-seconds, equivalent to 90 degrees when using the Arduino Servo library // The Servo library is not used in order to avoid future interrupt conflicts. char thisrobot[] ="BambinoPM "; char thisprog[] ="B_PM01_ServosMid"; // Binary sketch size: 2,710 bytes (of a 30,720 byte maximum) //=========================================================== /**New* const byte servoRollPin =6; //Roll servo on pin 6 const byte servoPacePin =7; //Pace servo on pin 7 const byte redLEDpin =4; //red LED on pin 4, HIGH=on void ServoPulse(byte Spin, int Spulse) // pulse servo, Sctrl in degrees */ //=========================================================== // Pins const byte servoRollPin =6; //Roll servo on pin 6 const byte servoPacePin =7; //Pace servo on pin 7 const byte redLEDpin =4; //red LED on pin 4, HIGH=on //----------------------------------------------------------- // Variables byte rollC =90; // roll centre = 90 degrees (ie 1500us) => upright byte paceC =90; // pace centre = 90 degrees (ie 1500us) => feet together //=========================================================== void setup() { Serial.begin(9600); // to communicate with Serial Monitor Serial.print(thisrobot); // so we know which robot the program is for Serial.print(" "); Serial.println(thisprog); // so we know which program is running pinMode(servoRollPin, OUTPUT); // sets the digital pin as output digitalWrite(servoRollPin, LOW); // initialise pin pinMode(servoPacePin, OUTPUT); // sets the digital pin as output digitalWrite(servoPacePin, LOW); // initialise pin pinMode(redLEDpin, OUTPUT); // sets the digital pin as output digitalWrite(redLEDpin, HIGH); // turn ON red LED to show board is on } //----------------------------------------------------------- void loop() { ServoPulse(servoRollPin,rollC); // tell servo to go to position rollC ServoPulse(servoPacePin,paceC); // tell servo to go to position paceC delay(200); // waits 200 ms - do it slowly } //=========================================================== void ServoPulse(byte Spin, int Spulse) // pulse servo, Sctrl in degrees // Servos are controlled by a pulse of between 1000 and 2000 micro-seconds // giving a nominal travel of 100 degrees. The pulse is repeated about // every 20 milliseconds (the repeat interval is not critical). // Hence mid travel of the servo is given by a 1500 micro-seconds pulse // and a 10 micro-seconds pulse difference results in one degree nominal travel. // Servos can have about 180 degree travel depending on the servo type. // In Arduino sketches servo positions are often given in degrees with // 90 degrees as the mid range position. // If 90 degrees is given by a 1500 micro-second pulse // then zero degrees is 1500-(90*10) =600 micro-seconds // so a position of X degrees is given by a pulse of 600+(X*10) micro-seconds. // { // Servo values are in degrees, centre at 90, 10us per degree digitalWrite(Spin,HIGH); delayMicroseconds(Spulse *10 +600); // *10+600 to change to micro-seconds digitalWrite(Spin,LOW); } //===========================================================