Enroute N-B4726 Test interface program
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include <iostream> 00003 00004 using namespace std; 00005 00006 PwmOut myservo(p21); 00007 Serial pc(USBTX, USBRX); 00008 00009 const int maxPW = 2000; 00010 const int neutralPW = 1500; 00011 const int minPW = 1000; 00012 const int period = 20; //ms 50Hz 00013 00014 void limit(int &pw){ 00015 if (pw > maxPW) 00016 pw = maxPW; 00017 if (pw < minPW) 00018 pw = minPW; 00019 } 00020 00021 int pulseWidth = neutralPW; 00022 00023 int main() { 00024 pc.baud(115200); 00025 cout << "MBED ESC Interface:\r" << endl; 00026 cout << "Pulsewidth range: " << minPW << " - " << maxPW << "us\r" << endl; 00027 cout << "1,2,3 - PulseWidth (min, neutral, Max)\r" << endl; 00028 cout << "a,s, z,x - PulseWidth (-10, + 10, -1, +1)\r" << endl; 00029 00030 myservo.period_ms(period); // 50Hz 00031 myservo.pulsewidth_us(pulseWidth); // neutral 00032 00033 while(1) { 00034 cout << "Current pulsewidth: " << pulseWidth << "us \r" << endl; 00035 switch(pc.getc()) { 00036 case '1': 00037 pulseWidth = minPW; 00038 break; 00039 case '2': 00040 pulseWidth = neutralPW; 00041 break; 00042 case '3': 00043 pulseWidth = maxPW; 00044 break; 00045 case 'a': 00046 pulseWidth -= 10; 00047 limit(pulseWidth); 00048 break; 00049 case 's': 00050 pulseWidth += 10; 00051 limit(pulseWidth); 00052 break; 00053 case 'z': 00054 pulseWidth -= 1; 00055 limit(pulseWidth); 00056 break; 00057 case 'x': 00058 pulseWidth += 1; 00059 limit(pulseWidth); 00060 break; 00061 } 00062 00063 myservo.pulsewidth_us(pulseWidth); 00064 00065 } 00066 }
Generated on Wed Jul 13 2022 22:01:34 by
1.7.2