![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main.cpp@0:c055a2cae8b6, 2011-10-17 (annotated)
- Committer:
- gbeardall
- Date:
- Mon Oct 17 10:42:30 2011 +0000
- Revision:
- 0:c055a2cae8b6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gbeardall | 0:c055a2cae8b6 | 1 | /* |
gbeardall | 0:c055a2cae8b6 | 2 | * servo1: main.cpp - test program |
gbeardall | 0:c055a2cae8b6 | 3 | * |
gbeardall | 0:c055a2cae8b6 | 4 | */ |
gbeardall | 0:c055a2cae8b6 | 5 | |
gbeardall | 0:c055a2cae8b6 | 6 | #include <assert.h> |
gbeardall | 0:c055a2cae8b6 | 7 | |
gbeardall | 0:c055a2cae8b6 | 8 | #include "mbed.h" |
gbeardall | 0:c055a2cae8b6 | 9 | #include "Servo.h" |
gbeardall | 0:c055a2cae8b6 | 10 | |
gbeardall | 0:c055a2cae8b6 | 11 | DigitalOut led1(LED1); |
gbeardall | 0:c055a2cae8b6 | 12 | DigitalOut led2(LED2); |
gbeardall | 0:c055a2cae8b6 | 13 | DigitalOut led3(LED3); |
gbeardall | 0:c055a2cae8b6 | 14 | DigitalOut led4(LED4); |
gbeardall | 0:c055a2cae8b6 | 15 | |
gbeardall | 0:c055a2cae8b6 | 16 | Serial pc(USBTX,USBRX); |
gbeardall | 0:c055a2cae8b6 | 17 | |
gbeardall | 0:c055a2cae8b6 | 18 | Servo servo(p21); |
gbeardall | 0:c055a2cae8b6 | 19 | |
gbeardall | 0:c055a2cae8b6 | 20 | // --------------------------------------------------------------------------- |
gbeardall | 0:c055a2cae8b6 | 21 | |
gbeardall | 0:c055a2cae8b6 | 22 | int main() { |
gbeardall | 0:c055a2cae8b6 | 23 | |
gbeardall | 0:c055a2cae8b6 | 24 | pc.printf("\n\rStart: servo1\n\r"); |
gbeardall | 0:c055a2cae8b6 | 25 | |
gbeardall | 0:c055a2cae8b6 | 26 | // sweep servo |
gbeardall | 0:c055a2cae8b6 | 27 | for(int i=0; i<1; ++i) { |
gbeardall | 0:c055a2cae8b6 | 28 | |
gbeardall | 0:c055a2cae8b6 | 29 | for( float p=0; p<=1.0; p+=0.01) { |
gbeardall | 0:c055a2cae8b6 | 30 | servo = p; |
gbeardall | 0:c055a2cae8b6 | 31 | wait(0.01); |
gbeardall | 0:c055a2cae8b6 | 32 | } // for |
gbeardall | 0:c055a2cae8b6 | 33 | |
gbeardall | 0:c055a2cae8b6 | 34 | for( float p=1.0; p>=0; p-=0.01) { |
gbeardall | 0:c055a2cae8b6 | 35 | servo = p; |
gbeardall | 0:c055a2cae8b6 | 36 | wait(0.01); |
gbeardall | 0:c055a2cae8b6 | 37 | } // for |
gbeardall | 0:c055a2cae8b6 | 38 | |
gbeardall | 0:c055a2cae8b6 | 39 | } // for - i |
gbeardall | 0:c055a2cae8b6 | 40 | |
gbeardall | 0:c055a2cae8b6 | 41 | fprintf(stdout, "stdout1\n\r"); |
gbeardall | 0:c055a2cae8b6 | 42 | fprintf(stderr, "stderr1\n\r"); |
gbeardall | 0:c055a2cae8b6 | 43 | |
gbeardall | 0:c055a2cae8b6 | 44 | assert(1); // if false; just exits (no msg to stderr) |
gbeardall | 0:c055a2cae8b6 | 45 | |
gbeardall | 0:c055a2cae8b6 | 46 | fprintf(stdout, "stdout2\n\r"); |
gbeardall | 0:c055a2cae8b6 | 47 | fprintf(stderr, "stderr2\n\r"); |
gbeardall | 0:c055a2cae8b6 | 48 | |
gbeardall | 0:c055a2cae8b6 | 49 | exit(0); |
gbeardall | 0:c055a2cae8b6 | 50 | |
gbeardall | 0:c055a2cae8b6 | 51 | } // main |
gbeardall | 0:c055a2cae8b6 | 52 | |
gbeardall | 0:c055a2cae8b6 | 53 | // --------------------------------------------------------------------------- |
gbeardall | 0:c055a2cae8b6 | 54 |