
DigitalSignal_Lab
Dependencies: LCD_DISCO_F746NG BSP_DISCO_F746NG Graphics
main.cpp@12:bf80826aed9f, 2019-08-31 (annotated)
- Committer:
- ngtkien
- Date:
- Sat Aug 31 03:12:26 2019 +0000
- Revision:
- 12:bf80826aed9f
- Parent:
- 10:ec6798bd4cfb
change wait_ms to wait_ns
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ngtkien95@gmail.com | 2:447f54400c21 | 1 | /* mbed Microcontroller Library |
ngtkien95@gmail.com | 2:447f54400c21 | 2 | * Copyright (c) 2018 ARM Limited |
ngtkien95@gmail.com | 2:447f54400c21 | 3 | * SPDX-License-Identifier: Apache-2.0 |
ngtkien95@gmail.com | 2:447f54400c21 | 4 | */ |
ngtkien | 0:612209585c31 | 5 | |
ngtkien95@gmail.com | 2:447f54400c21 | 6 | #include "mbed.h" |
ngtkien95@gmail.com | 2:447f54400c21 | 7 | #include "stats_report.h" |
ngtkien95@gmail.com | 2:447f54400c21 | 8 | #include "Graphics/RK043FN48H.h" |
ngtkien95@gmail.com | 3:297f513b26fe | 9 | #include "LCD_DISCO_F746NG/LCD_DISCO_F746NG.h" |
ngtkien | 0:612209585c31 | 10 | |
ngtkien95@gmail.com | 3:297f513b26fe | 11 | RK043FN48H graphics; |
ngtkien95@gmail.com | 3:297f513b26fe | 12 | LCD_DISCO_F746NG lcd; |
ngtkien | 0:612209585c31 | 13 | |
ngtkien95@gmail.com | 2:447f54400c21 | 14 | DigitalOut led1(LED1); |
ngtkien | 0:612209585c31 | 15 | |
ngtkien | 0:612209585c31 | 16 | |
ngtkien95@gmail.com | 3:297f513b26fe | 17 | |
ngtkien95@gmail.com | 3:297f513b26fe | 18 | #define SLEEP_TIME 200 // (msec) |
ngtkien95@gmail.com | 2:447f54400c21 | 19 | #define PRINT_AFTER_N_LOOPS 20 |
ngtkien | 0:612209585c31 | 20 | |
ngtkien95@gmail.com | 2:447f54400c21 | 21 | // main() runs in its own thread in the OS |
ngtkien | 0:612209585c31 | 22 | int main() |
ngtkien | 0:612209585c31 | 23 | { |
ngtkien95@gmail.com | 2:447f54400c21 | 24 | SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */); |
ngtkien | 0:612209585c31 | 25 | |
ngtkien95@gmail.com | 3:297f513b26fe | 26 | // display.Clear(LCD_COLOR_RED); |
ngtkien95@gmail.com | 3:297f513b26fe | 27 | |
ngtkien95@gmail.com | 3:297f513b26fe | 28 | graphics.SetActiveLayer(Background); |
ngtkien95@gmail.com | 3:297f513b26fe | 29 | graphics.SetBackgroundColor(LCD_COLOR_BLACK); |
ngtkien95@gmail.com | 3:297f513b26fe | 30 | graphics.SetActiveLayer(Foreground); |
ngtkien95@gmail.com | 3:297f513b26fe | 31 | |
ngtkien95@gmail.com | 3:297f513b26fe | 32 | |
ngtkien95@gmail.com | 3:297f513b26fe | 33 | graphics.SetBackColor(LCD_COLOR_BLACK); |
ngtkien95@gmail.com | 3:297f513b26fe | 34 | graphics.SetTextColor(LCD_COLOR_LIGHTGRAY); |
ngtkien95@gmail.com | 3:297f513b26fe | 35 | graphics.DisplayStringAt(10, 10, (unsigned char*)TITLE, CENTER_MODE); |
ngtkien95@gmail.com | 7:c8ddf2b6aaec | 36 | graphics.DisplayStringAt(10, 70, (unsigned char*)TITLE, CENTER_MODE); |
ngtkien95@gmail.com | 7:c8ddf2b6aaec | 37 | graphics.DisplayStringAt(10, 40, (unsigned char*)TITLE, CENTER_MODE); |
ngtkien95@gmail.com | 3:297f513b26fe | 38 | |
ngtkien95@gmail.com | 3:297f513b26fe | 39 | int xrand = 0,yrand = 0; |
ngtkien95@gmail.com | 3:297f513b26fe | 40 | uint32_t colorshift = LCD_COLOR_WHITE; |
ngtkien95@gmail.com | 2:447f54400c21 | 41 | int count = 0; |
ngtkien95@gmail.com | 2:447f54400c21 | 42 | while (true) { |
ngtkien95@gmail.com | 2:447f54400c21 | 43 | // Blink LED and wait 0.5 seconds |
ngtkien95@gmail.com | 2:447f54400c21 | 44 | led1 = !led1; |
ngtkien | 12:bf80826aed9f | 45 | wait_ns(SLEEP_TIME*100000); |
ngtkien95@gmail.com | 3:297f513b26fe | 46 | |
ngtkien95@gmail.com | 3:297f513b26fe | 47 | // xrand = 10 + std::rand()%470; |
ngtkien95@gmail.com | 3:297f513b26fe | 48 | // yrand = 10 + std::rand()%262; |
ngtkien95@gmail.com | 3:297f513b26fe | 49 | |
ngtkien95@gmail.com | 3:297f513b26fe | 50 | // colorshift = colorshift << (rand()%5); |
ngtkien95@gmail.com | 3:297f513b26fe | 51 | // colorshift = colorshift >> (rand()%3); |
ngtkien95@gmail.com | 3:297f513b26fe | 52 | // graphics.SetForegroundColor(colorshift); |
ngtkien95@gmail.com | 3:297f513b26fe | 53 | // graphics.FillCircle(xrand,yrand,5); |
ngtkien95@gmail.com | 2:447f54400c21 | 54 | |
ngtkien95@gmail.com | 2:447f54400c21 | 55 | if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) { |
ngtkien95@gmail.com | 2:447f54400c21 | 56 | // Following the main thread wait, report on the current system status |
ngtkien95@gmail.com | 2:447f54400c21 | 57 | sys_state.report_state(); |
ngtkien95@gmail.com | 2:447f54400c21 | 58 | count = 0; |
ngtkien95@gmail.com | 2:447f54400c21 | 59 | } |
ngtkien95@gmail.com | 2:447f54400c21 | 60 | ++count; |
ngtkien | 0:612209585c31 | 61 | } |
ngtkien | 0:612209585c31 | 62 | } |