Program to demonstrate lighting an led via a command line command

Dependencies:   LPS331_I2C

main.cpp

Committer:
bhimebau
Date:
2021-09-22
Revision:
0:f7d9662c6d11
Child:
1:48e24393d6d9

File content as of revision 0:f7d9662c6d11:

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#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

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

    // Initialise the digital pin LED1 as an output
    DigitalOut led(LED1);
    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;
        }
        pc.printf("\n\r",cmd);
        pc.printf("L432> ");
    }
}