Bryce Himebaugh / Mbed OS motor_buffer
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 #include "mbed.h"
00003 #include "platform/mbed_thread.h"
00004 #include <string.h>
00005 
00006 // PWM Frequency
00007 #define PFREQ .5
00008 
00009 
00010 Serial pc(USBTX, USBRX); // tx, rx
00011 PwmOut p1(PA_8);
00012 
00013 int main()
00014 {
00015     char cmd[80];
00016     char ch;
00017     unsigned char index = 0;
00018 
00019     // Initialise the digital pin LED1 as an output
00020     DigitalOut led(LED1);
00021     p1.period((float)1/PFREQ);
00022     p1.write(0.0);
00023     pc.printf("\n\rMotor> ");    
00024     while (true) {
00025         
00026         ch = pc.getc();
00027         index = 0;
00028         while ((ch != '\n') && (ch != '\r')) {
00029             pc.putc(ch);
00030             cmd[index++] = ch;
00031             ch = pc.getc();
00032         }   
00033         cmd[index] = 0;
00034         if (!strcmp(cmd,"lon")) {
00035             led = 1;
00036         }   
00037         else if (!strcmp(cmd,"lof")) {
00038             led = 0;
00039         }
00040         else if (!strcmp(cmd,"high")) {
00041             p1.write(1.0);  
00042         }
00043         else if (!strcmp(cmd,"med")) {
00044             p1.write(0.5);  
00045         }
00046         else if (!strcmp(cmd,"low")) {
00047             p1.write(0.15);  
00048         }
00049         else if (!strcmp(cmd,"off")) {
00050             p1.write(0.0);  
00051         }
00052         
00053         pc.printf("\n\r");
00054         pc.printf("Motor> ");
00055     }
00056 }
00057