The programme shows some of the features of the RenBuggyServo library in action.

Dependencies:   mbed

main.cpp

Committer:
Markatron
Date:
2014-03-07
Revision:
0:40e8ea905308
Child:
1:1a5db4892449

File content as of revision 0:40e8ea905308:

/*******************************************************************************
* This program demonstrates how to drive the RenBuggy_Servo
* using the Car library.
* 
* Mark Jones 
* V1.0 05/03/2014
*******************************************************************************/

#include "mbed.h"
#include "Car.h"

Car myCar(P1_25, P1_24);

// Main entry point of application.
int main() {
    
    const int SERVO_PWM = 1500;             // 1500 = centre.
    const int SERVO_PWM_PERIOD = 2000;  
    const int SERVO_PWM_RANGE = 500;        // + or - 500 microseconds.
    const float SERVO_DEGREES_RANGE = 45.0; // + or - from centre is full right/left.
    
    const int MOTOR_PWM = 20000;
    const int MOTOR_PERIOD = 20000;
    
    // Configure the servo and motor before use.
    myCar.configureServo_us(SERVO_PWM, SERVO_PWM_PERIOD, 
    SERVO_PWM_RANGE, SERVO_DEGREES_RANGE);
    
    myCar.configureMotor_us(MOTOR_PWM, MOTOR_PERIOD);
    
    // Drive the RenBuggy!
    myCar.setDirection(0);
    wait(1);
    myCar.forwards();
    wait(4);
    myCar.setDirection(45);
    wait(8);
    myCar.setDirection(0);
    wait(4);
    myCar.setDirection(-45);
    wait(8);
    myCar.stop();
}