Gorazd Kovacic
/
mbed-os-example-blinky-LIGHTNING_copy
test
Diff: main.cpp
- Revision:
- 43:bda92a299378
- Parent:
- 32:0b58d21e87d6
- Child:
- 44:50aa0a0d1222
--- a/main.cpp Thu Jun 22 09:00:02 2017 +0100 +++ b/main.cpp Sun Jun 02 08:52:41 2019 +0000 @@ -1,12 +1,92 @@ #include "mbed.h" +//Program to 'sweep' test a 'standard RC type servo +//Define some parameters using compiler directive '#define' +//Check Servo DATA if 0.75ms to 2.25ms then use min=750 and max=2250 +//NB be values in microseconds (Following are generic values) +#define MID 1500 +#define MIN 544 +#define MAX 2400 +#define STEP 50 +//Time delay between steps in milliseconds +#define TIME 20 //100 + -DigitalOut led1(LED1); +#define DELTA 50 + +DigitalOut myLed(LED1); +DigitalIn myButton(USER_BUTTON); + +PwmOut myServo(D3); + + + -// main() runs in its own thread in the OS + void motor_on(void) + { + + //myServo.period_ms(20); + myServo.pulsewidth_us(MID); //NB in microseconds + + } + + void motor_off(void) + { + myServo.pulsewidth_us(MIN+2*DELTA); //NB in microseconds + } + + + int main() { - while (true) { - led1 = !led1; - wait(0.5); + + wait(3); // if (myButton) + + + while (0) + { + for (int i=0; i<1000;i++) + { + wait_ms(20); + motor_on(); + } + + for (int i=0; i<1000;i++) + { + wait_ms(20); + motor_off(); + } + + } + + + while (1) + { + + for (int i=0; i<50*3; i++) + { + //myServo.period_ms(20); + myServo.pulsewidth_us(MIN); //NB in microseconds + wait_ms(TIME); } -} - + + for (int i=0; i<50*3; i++) + { + //myServo.period_ms(20); + myServo.pulsewidth_us(MID); //NB in microseconds + wait_ms(TIME); + } + + + } + /* + while(true) { + for (int i=MIN;i<=MAX;i+=STEP){ + myServo.pulsewidth_us(i); + wait_ms(TIME); + } + for (int i=MAX;i>=MIN;i-=STEP){ + myServo.pulsewidth_us(i); + wait_ms(TIME); + } + */ + +} \ No newline at end of file