Pager Motor Example

main.cpp

Committer:
bhimebau
Date:
2021-12-03
Revision:
2:007b4fa1f64e
Parent:
1:48e24393d6d9
Child:
3:2e70eaa59446

File content as of revision 2:007b4fa1f64e:


#include "mbed.h"
#include "platform/mbed_thread.h"
#include <string.h>

// Blinking rate in milliseconds
#define BLINKING_RATE_MS                                                    500

Serial pc(USBTX, USBRX); // tx, rx
PwmOut p1(PA_8);

int main()
{
    char cmd[80];
    char ch;
    unsigned char index = 0;

    // Initialise the digital pin LED1 as an output
    DigitalOut led(LED1);
    
    p1.write(0.0);
    pc.printf("L432> ");    
    while (true) {
        
        ch = pc.getc();
        index = 0;
        while ((ch != '\n') && (ch != '\r')) {
            pc.putc(ch);
            cmd[index++] = ch;
            ch = pc.getc();
        }   
        cmd[index] = 0;
        if (!strcmp(cmd,"lon")) {
            led = 1;
        }   
        else if (!strcmp(cmd,"lof")) {
            led = 0;
        }
        else if (!strcmp(cmd,"monh")) {
            p1.write(1.0);  
        }
        else if (!strcmp(cmd,"monm")) {
            p1.write(0.5);  
        }
        else if (!strcmp(cmd,"monl")) {
            p1.write(0.15);  
        }
        else if (!strcmp(cmd,"mof")) {
            p1.write(0.0);  
        }
        
        pc.printf("\n\r");
        pc.printf("L432> ");
    }
}