// main.cpp

/*
 * Copyright (c) 2020 Arm Limited and affiliates.
 * SPDX-License-Identifier: Apache-2.0
 */
#include "mbed.h"

DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalIn  button(PC_13);

Thread thread;
#define MAXIMUM_BUFFER_SIZE 32

volatile bool led_on = false;
EventFlags flag;

static BufferedSerial serial_port(USBTX, USBRX);

void led2_thread() {
  serial_port.set_baud(9600);
  serial_port.set_format(
      /* bits */ 8,
      /* parity */ BufferedSerial::None,
      /* stop bit */ 1);
  while (true) {

    if (uint32_t num = serial_port.read(buf, sizeof(buf))) {
      // Echo the input back to the terminal.
      serial_port.write(buf, num_presses);
    }

    thread.start(led2_thread);
    led2 = !led2;
    ThisThread::sleep_for(1000);
  }
}

int main()
{

    while (true) {
        led1 = !led1;
        ThisThread::sleep_for(500);
    }
}
