Timothé Turko / Mbed 2 deprecated Nucleo_hyperterminal_LED

Dependencies:   mbed

main.cpp

Committer:
ygendrault
Date:
2017-12-15
Revision:
0:fe8a2e63737f

File content as of revision 0:fe8a2e63737f:

#include "mbed.h"

Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut led(LED1);
int test = 0;
char previous = 0;

int main()
{
    pc.printf("Press '1' to turn LED1 ON, '0' to turn it OFF\n");
    while(1) {
        char c = pc.getc(); // Read hyperterminal
        if (c == '0') {
            if (previous=='1')
                {
                    test =0;
                }
            if (test==0)
                {
                    test=1;
                    previous = '0';
                    led = 0; // OFF
                }
            else
                {
                    pc.printf("LED already OFF\n");
                }
        }
        if (c == '1') {
            if (previous=='0')
                {
                    test =0;
                }
            if (test==0)
                {
                    test=1;
                    previous = '1';
                    led = 1; // OFF
                }
            else
                {
                    pc.printf("LED already ON\n");
                }
        }
    }
}