Program to demonstrate lighting an led via a command line command

Dependencies:   LPS331_I2C

Committer:
bhimebau
Date:
Wed Sep 22 13:41:56 2021 +0000
Revision:
0:f7d9662c6d11
Child:
1:48e24393d6d9
simple terminal ;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bhimebau 0:f7d9662c6d11 1 /* mbed Microcontroller Library
bhimebau 0:f7d9662c6d11 2 * Copyright (c) 2019 ARM Limited
bhimebau 0:f7d9662c6d11 3 * SPDX-License-Identifier: Apache-2.0
bhimebau 0:f7d9662c6d11 4 */
bhimebau 0:f7d9662c6d11 5
bhimebau 0:f7d9662c6d11 6 #include "mbed.h"
bhimebau 0:f7d9662c6d11 7 #include "platform/mbed_thread.h"
bhimebau 0:f7d9662c6d11 8 #include <string.h>
bhimebau 0:f7d9662c6d11 9
bhimebau 0:f7d9662c6d11 10
bhimebau 0:f7d9662c6d11 11 // Blinking rate in milliseconds
bhimebau 0:f7d9662c6d11 12 #define BLINKING_RATE_MS 500
bhimebau 0:f7d9662c6d11 13
bhimebau 0:f7d9662c6d11 14 Serial pc(USBTX, USBRX); // tx, rx
bhimebau 0:f7d9662c6d11 15
bhimebau 0:f7d9662c6d11 16 int main()
bhimebau 0:f7d9662c6d11 17 {
bhimebau 0:f7d9662c6d11 18 char cmd[80];
bhimebau 0:f7d9662c6d11 19 char ch;
bhimebau 0:f7d9662c6d11 20 unsigned char index = 0;
bhimebau 0:f7d9662c6d11 21
bhimebau 0:f7d9662c6d11 22 // Initialise the digital pin LED1 as an output
bhimebau 0:f7d9662c6d11 23 DigitalOut led(LED1);
bhimebau 0:f7d9662c6d11 24 pc.printf("L432> ");
bhimebau 0:f7d9662c6d11 25 while (true) {
bhimebau 0:f7d9662c6d11 26
bhimebau 0:f7d9662c6d11 27 ch = pc.getc();
bhimebau 0:f7d9662c6d11 28 index = 0;
bhimebau 0:f7d9662c6d11 29 while ((ch != '\n') && (ch != '\r')) {
bhimebau 0:f7d9662c6d11 30 pc.putc(ch);
bhimebau 0:f7d9662c6d11 31 cmd[index++] = ch;
bhimebau 0:f7d9662c6d11 32 ch = pc.getc();
bhimebau 0:f7d9662c6d11 33 }
bhimebau 0:f7d9662c6d11 34 cmd[index] = 0;
bhimebau 0:f7d9662c6d11 35 if (!strcmp(cmd,"lon")) {
bhimebau 0:f7d9662c6d11 36 led = 1;
bhimebau 0:f7d9662c6d11 37 }
bhimebau 0:f7d9662c6d11 38 else if (!strcmp(cmd,"lof")) {
bhimebau 0:f7d9662c6d11 39 led = 0;
bhimebau 0:f7d9662c6d11 40 }
bhimebau 0:f7d9662c6d11 41 pc.printf("\n\r",cmd);
bhimebau 0:f7d9662c6d11 42 pc.printf("L432> ");
bhimebau 0:f7d9662c6d11 43 }
bhimebau 0:f7d9662c6d11 44 }