A simple API/Software interface to the LPC17xx PWM peripheral to provide control to up to six RC type servo controllers.
inc/example2.h@3:1232505e7206, 2011-05-19 (annotated)
- Committer:
- AjK
- Date:
- Thu May 19 22:48:17 2011 +0000
- Revision:
- 3:1232505e7206
1.3 See ChangeLog.h
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
AjK | 3:1232505e7206 | 1 | /* |
AjK | 3:1232505e7206 | 2 | Copyright (c) 2011 Andy Kirkham |
AjK | 3:1232505e7206 | 3 | |
AjK | 3:1232505e7206 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy |
AjK | 3:1232505e7206 | 5 | of this software and associated documentation files (the "Software"), to deal |
AjK | 3:1232505e7206 | 6 | in the Software without restriction, including without limitation the rights |
AjK | 3:1232505e7206 | 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
AjK | 3:1232505e7206 | 8 | copies of the Software, and to permit persons to whom the Software is |
AjK | 3:1232505e7206 | 9 | furnished to do so, subject to the following conditions: |
AjK | 3:1232505e7206 | 10 | |
AjK | 3:1232505e7206 | 11 | The above copyright notice and this permission notice shall be included in |
AjK | 3:1232505e7206 | 12 | all copies or substantial portions of the Software. |
AjK | 3:1232505e7206 | 13 | |
AjK | 3:1232505e7206 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
AjK | 3:1232505e7206 | 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
AjK | 3:1232505e7206 | 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
AjK | 3:1232505e7206 | 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
AjK | 3:1232505e7206 | 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
AjK | 3:1232505e7206 | 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
AjK | 3:1232505e7206 | 20 | THE SOFTWARE. |
AjK | 3:1232505e7206 | 21 | */ |
AjK | 3:1232505e7206 | 22 | |
AjK | 3:1232505e7206 | 23 | // Dervived from http://mbed.org/forum/helloworld/topic/2303 |
AjK | 3:1232505e7206 | 24 | |
AjK | 3:1232505e7206 | 25 | #include "mbed.h" |
AjK | 3:1232505e7206 | 26 | |
AjK | 3:1232505e7206 | 27 | DigitalOut led1(LED1); |
AjK | 3:1232505e7206 | 28 | DigitalOut led2(LED2); |
AjK | 3:1232505e7206 | 29 | |
AjK | 3:1232505e7206 | 30 | #include "SimpleRCservos.h" |
AjK | 3:1232505e7206 | 31 | #include "SimpleServoControl.h" |
AjK | 3:1232505e7206 | 32 | |
AjK | 3:1232505e7206 | 33 | SimpleRCservos servos; |
AjK | 3:1232505e7206 | 34 | |
AjK | 3:1232505e7206 | 35 | SimpleServoControl motor_front_left(&servos, SimpleRCservos::Servo6); // p21 |
AjK | 3:1232505e7206 | 36 | SimpleServoControl motor_front_right(&servos, SimpleRCservos::Servo5); // p22 |
AjK | 3:1232505e7206 | 37 | SimpleServoControl motor_rear_left(&servos, SimpleRCservos::Servo4); // p23 |
AjK | 3:1232505e7206 | 38 | SimpleServoControl motor_rear_right(&servos, SimpleRCservos::Servo3); // p24 |
AjK | 3:1232505e7206 | 39 | |
AjK | 3:1232505e7206 | 40 | int main() |
AjK | 3:1232505e7206 | 41 | { |
AjK | 3:1232505e7206 | 42 | // Led1 on to show program start. |
AjK | 3:1232505e7206 | 43 | led1 = 1; |
AjK | 3:1232505e7206 | 44 | |
AjK | 3:1232505e7206 | 45 | motor_front_left.position(90.0); |
AjK | 3:1232505e7206 | 46 | motor_front_right.position(90.0); |
AjK | 3:1232505e7206 | 47 | motor_rear_left.position(90.0); |
AjK | 3:1232505e7206 | 48 | motor_rear_right.position(90.0); |
AjK | 3:1232505e7206 | 49 | |
AjK | 3:1232505e7206 | 50 | // Led2 on when rotate complete and program ended. |
AjK | 3:1232505e7206 | 51 | led2 = 1; |
AjK | 3:1232505e7206 | 52 | |
AjK | 3:1232505e7206 | 53 | // End, loop forever. |
AjK | 3:1232505e7206 | 54 | while(1); |
AjK | 3:1232505e7206 | 55 | } |