CITY1082 code example

main.cpp

Committer:
reedas
Date:
2019-11-05
Revision:
102:17e6fc7c4be0
Parent:
100:ec006d6f3cb6
Child:
103:decc5a1b2e80

File content as of revision 102:17e6fc7c4be0:

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

#include "mbed.h"
#include "platform/mbed_thread.h"
#include "stats_report.h"

DigitalOut RedLED(LED1);
DigitalOut GreenLED(LED2);
DigitalOut BlueLED(LED3);
DigitalOut led1(LED4);
DigitalOut led2(LED5);

#define SLEEP_TIME                  500 // (msec)
#define PRINT_AFTER_N_LOOPS         20

// main() runs in its own thread in the OS
int main()
{
    SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);

    int count = 0;
    while (true) {
        // Blink LED and wait 0.5 seconds
        led1 = !led1;
        led2 = !led2;
        RedLED = !RedLED;
        GreenLED = !GreenLED;
        BlueLED = !BlueLED;
        thread_sleep_for(SLEEP_TIME);

        if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
            // Following the main thread wait, report on the current system status
            sys_state.report_state();
            count = 0;
        }
        ++count;
    }
}