Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HW5_Servo by
main.cpp@2:13e9c2f5ca10, 2014-11-10 (annotated)
- Committer:
- adarsh5723
- Date:
- Mon Nov 10 11:31:24 2014 +0000
- Revision:
- 2:13e9c2f5ca10
- Parent:
- 1:19dd18051447
KL25Z firmware.; Responsible for activating the servo based on input from the nRF51822.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| sunitav | 0:9898eeeb7143 | 1 | // Hello World to sweep a servo through its full range |
| sunitav | 0:9898eeeb7143 | 2 | |
| sunitav | 0:9898eeeb7143 | 3 | #include "mbed.h" |
| sunitav | 0:9898eeeb7143 | 4 | #include "Servo.h" |
| sunitav | 0:9898eeeb7143 | 5 | |
| adarsh5723 | 1:19dd18051447 | 6 | |
| adarsh5723 | 2:13e9c2f5ca10 | 7 | #define DEBUG 0 |
| adarsh5723 | 1:19dd18051447 | 8 | |
| adarsh5723 | 1:19dd18051447 | 9 | DigitalIn toggleSwitch(D3); |
| adarsh5723 | 2:13e9c2f5ca10 | 10 | //debugging Analog in |
| adarsh5723 | 1:19dd18051447 | 11 | AnalogIn ldr0(A5); |
| adarsh5723 | 1:19dd18051447 | 12 | PwmOut servoDriver(D2); |
| sunitav | 0:9898eeeb7143 | 13 | Servo myservo(D2); //change digital pin here |
| adarsh5723 | 1:19dd18051447 | 14 | |
| sunitav | 0:9898eeeb7143 | 15 | |
| adarsh5723 | 1:19dd18051447 | 16 | Serial pc(USBTX, USBRX); |
| sunitav | 0:9898eeeb7143 | 17 | int main() { |
| adarsh5723 | 1:19dd18051447 | 18 | //myservo.position(270.0f); |
| adarsh5723 | 1:19dd18051447 | 19 | myservo.calibrate(.0006, 120.0); |
| adarsh5723 | 1:19dd18051447 | 20 | bool servoLogic = 0; |
| adarsh5723 | 1:19dd18051447 | 21 | |
| sunitav | 0:9898eeeb7143 | 22 | while(1){ |
| adarsh5723 | 1:19dd18051447 | 23 | if (toggleSwitch == 1) |
| adarsh5723 | 1:19dd18051447 | 24 | //if (ldr0.read() > 0.7) |
| adarsh5723 | 1:19dd18051447 | 25 | servoLogic = 1; |
| adarsh5723 | 1:19dd18051447 | 26 | else |
| adarsh5723 | 1:19dd18051447 | 27 | servoLogic = 0; |
| sunitav | 0:9898eeeb7143 | 28 | //recieve_data(ServoLogic); |
| adarsh5723 | 1:19dd18051447 | 29 | if (servoLogic) |
| sunitav | 0:9898eeeb7143 | 30 | { |
| adarsh5723 | 2:13e9c2f5ca10 | 31 | myservo = 0.0f; |
| sunitav | 0:9898eeeb7143 | 32 | } |
| sunitav | 0:9898eeeb7143 | 33 | else{ |
| adarsh5723 | 2:13e9c2f5ca10 | 34 | |
| adarsh5723 | 2:13e9c2f5ca10 | 35 | myservo = 1.0f; |
| sunitav | 0:9898eeeb7143 | 36 | } |
| adarsh5723 | 2:13e9c2f5ca10 | 37 | //For debugging purposes |
| adarsh5723 | 2:13e9c2f5ca10 | 38 | #if DEBUG |
| adarsh5723 | 1:19dd18051447 | 39 | printf("%f\n\r",ldr0.read()); |
| adarsh5723 | 1:19dd18051447 | 40 | #endif |
| sunitav | 0:9898eeeb7143 | 41 | wait(.2); |
| sunitav | 0:9898eeeb7143 | 42 | } |
| sunitav | 0:9898eeeb7143 | 43 | } |
