Israel Hernández Orozco / Mbed 2 deprecated 7_4

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 //Program to 'sweep' test a 'standard RC type servo
00003 //Define some parameters using compiler directive '#define'
00004 //Check Servo DATA if 0.75ms to 2.25ms then use min=750 and max=2250
00005 //NB be values in microseconds (Following are generic values)
00006 #define MID         1500
00007 #define MIN         1000
00008 #define MAX         2000
00009 #define STEP          50
00010 #define TIME         100
00011 PwmOut myServo(D5);
00012 InterruptIn Incrementa(USER_BUTTON);
00013 InterruptIn Decrementa(D15);
00014 void dispara1() {       
00015         for (int i=MIN;i<=MAX;i+=STEP){
00016             myServo.pulsewidth_us(i);
00017             wait_ms(TIME);
00018         }
00019 }
00020 void dispara2() {
00021         for (int i=MAX;i>=MIN;i-=STEP){
00022             myServo.pulsewidth_us(i);
00023             wait_ms(TIME);
00024         }
00025 }
00026 
00027 int main() {
00028 myServo.period_ms(20);
00029 while(true) {
00030     Decrementa.fall(&dispara1);
00031     Incrementa.fall(&dispara2);
00032     }
00033 }