The programme shows some of the features of the RenBuggyServo library in action.
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /******************************************************************************* 00002 * This program demonstrates how to drive the RenBuggy_Servo 00003 * using the Car library. 00004 * 00005 * Mark Jones 00006 * V1.0 05/03/2014 00007 *******************************************************************************/ 00008 00009 #include "mbed.h" 00010 #include "Car.h" 00011 00012 Car myCar(P1_26, P1_24, 16, 16.65f, P0_7); 00013 00014 // Main entry point of application. 00015 int main() { 00016 00017 const int SERVO_PWM = 1500; // 1500 = centre. 00018 const int SERVO_PWM_PERIOD = 2000; 00019 const int SERVO_PWM_RANGE = 500; // + or - 500 microseconds. 00020 const float SERVO_DEGREES_RANGE = 45.0; // + or - from centre is full right/left. 00021 00022 const int MOTOR_PWM = 20000; 00023 const int MOTOR_PERIOD = 20000; 00024 00025 // Configure the servo and motor before use. 00026 myCar.configureServo_us(SERVO_PWM, SERVO_PWM_PERIOD, 00027 SERVO_PWM_RANGE, SERVO_DEGREES_RANGE); 00028 00029 myCar.configureMotor_us(MOTOR_PWM, MOTOR_PERIOD); 00030 00031 myCar.setDirection(0); 00032 00033 myCar.forwards(7); 00034 myCar.setDirection(45); 00035 myCar.forwards(20); 00036 myCar.setDirection(-30); 00037 myCar.forwards(20); 00038 }
Generated on Mon Jul 25 2022 00:52:29 by
1.7.2