Nuvoton
/
NuMaker-mbed-GPIO-button-buzzer-rgbled
NuMaker GPIO button with LED and buzzer
main.cpp@13:9982ee238f27, 2021-02-25 (annotated)
- Committer:
- SHLIU1@OANBE02333.nuvoton.com
- Date:
- Thu Feb 25 10:55:25 2021 +0800
- Revision:
- 13:9982ee238f27
- Parent:
- 11:9a0562f4e236
Support the both V5.X and V6.X for mbed-os
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 0:f700c61f47e5 | 1 | #include "mbed.h" |
ccli8 |
11:9a0562f4e236 | 2 | |
shliu1 |
5:4a573124ab4a | 3 | #if defined(TARGET_NUMAKER_PFM_NUC472) |
ccli8 |
11:9a0562f4e236 | 4 | DigitalOut rgbled_B(LED_BLUE); // low-active |
ccli8 |
11:9a0562f4e236 | 5 | DigitalOut rgbled_R(LED_RED); // low-active |
ccli8 |
11:9a0562f4e236 | 6 | DigitalOut rgbled_G(LED_GREEN); // low-active |
ccli8 |
11:9a0562f4e236 | 7 | DigitalOut greenled(PG_0); // low-active |
ccli8 |
11:9a0562f4e236 | 8 | DigitalOut buzzer(PD_11); // low-active |
ccli8 |
11:9a0562f4e236 | 9 | DigitalIn button_SW1(SW1); // press button =0 |
ccli8 |
11:9a0562f4e236 | 10 | DigitalIn button_SW2(SW2); // press button =0 |
shliu1 |
5:4a573124ab4a | 11 | #elif defined(TARGET_NUMAKER_PFM_M453) |
ccli8 |
11:9a0562f4e236 | 12 | DigitalOut rgbled_B(LED_BLUE); // low-active |
ccli8 |
11:9a0562f4e236 | 13 | DigitalOut rgbled_R(LED_RED); // low-active |
ccli8 |
11:9a0562f4e236 | 14 | DigitalOut rgbled_G(LED_GREEN); // low-active |
ccli8 |
11:9a0562f4e236 | 15 | DigitalOut greenled(PB_12); // low-active |
ccli8 |
11:9a0562f4e236 | 16 | DigitalOut buzzer(PE_2); // low-active |
ccli8 |
11:9a0562f4e236 | 17 | DigitalIn button_SW1(SW2); // press button =0 |
ccli8 |
11:9a0562f4e236 | 18 | DigitalIn button_SW2(SW3); // press button =0 |
shliu1 |
8:876e8a140f39 | 19 | #elif defined(TARGET_NUMAKER_PFM_M487) |
ccli8 |
11:9a0562f4e236 | 20 | DigitalOut rgbled_B(LED_YELLOW); // in M487, rgbled_B is yellow, not blue, low-active |
ccli8 |
11:9a0562f4e236 | 21 | DigitalOut rgbled_R(LED_RED); // low-active |
ccli8 |
11:9a0562f4e236 | 22 | DigitalOut rgbled_G(LED_GREEN); // low-active |
ccli8 |
11:9a0562f4e236 | 23 | DigitalOut greenled(D2); // in M487, change the pin to match real hardware, low-active |
ccli8 |
11:9a0562f4e236 | 24 | DigitalOut buzzer(D3); // in M487, change the pin to match real hardware, low-active |
ccli8 |
11:9a0562f4e236 | 25 | DigitalIn button_SW1(SW2); // in M487, button_SW1 is SW2, press button =0 |
ccli8 |
11:9a0562f4e236 | 26 | DigitalIn button_SW2(SW3); // in M487, button_SW2 is SW3, press button =0 |
ccchang |
9:19b2945fefd4 | 27 | #elif defined(TARGET_NUMAKER_PFM_NANO130) |
ccli8 |
11:9a0562f4e236 | 28 | DigitalOut rgbled_B(LED_YELLOW); // in NANO130, rgbled_B is yellow, not blue, low-active |
ccli8 |
11:9a0562f4e236 | 29 | DigitalOut rgbled_R(LED_RED); // low-active |
ccli8 |
11:9a0562f4e236 | 30 | DigitalOut rgbled_G(LED_GREEN); // low-active |
ccli8 |
11:9a0562f4e236 | 31 | DigitalOut greenled(D2); // in NANO130, change the pin to match real hardware, low-active |
ccli8 |
11:9a0562f4e236 | 32 | DigitalOut buzzer(D3); // in NANO130, change the pin to match real hardware, low-active |
ccli8 |
11:9a0562f4e236 | 33 | DigitalIn button_SW1(SW1); // press button =0 |
ccli8 |
11:9a0562f4e236 | 34 | DigitalIn button_SW2(SW2); // press button =0 |
shliu1 |
5:4a573124ab4a | 35 | #endif |
rkuo2000 | 0:f700c61f47e5 | 36 | |
rkuo2000 | 0:f700c61f47e5 | 37 | // main() runs in its own thread in the OS |
shliu1 |
5:4a573124ab4a | 38 | // (note the calls to Thread::wait below for d elays) |
rkuo2000 | 0:f700c61f47e5 | 39 | int main() { |
rkuo2000 | 0:f700c61f47e5 | 40 | |
rkuo2000 | 0:f700c61f47e5 | 41 | rgbled_B=1; rgbled_R=1; rgbled_G=1; |
rkuo2000 | 0:f700c61f47e5 | 42 | greenled=1; |
rkuo2000 | 0:f700c61f47e5 | 43 | buzzer=1; |
SHLIU1@OANBE02333.nuvoton.com | 13:9982ee238f27 | 44 | #ifdef MBED_MAJOR_VERSION |
SHLIU1@OANBE02333.nuvoton.com | 13:9982ee238f27 | 45 | printf("Mbed OS version %d.%d.%d\r\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION); |
SHLIU1@OANBE02333.nuvoton.com | 13:9982ee238f27 | 46 | #endif |
rkuo2000 | 0:f700c61f47e5 | 47 | while (true) { |
rkuo2000 | 0:f700c61f47e5 | 48 | // press SW1 will turn on greeled and RGBLED=blue |
rkuo2000 | 0:f700c61f47e5 | 49 | if (button_SW1==0) { |
rkuo2000 | 0:f700c61f47e5 | 50 | greenled=0; |
rkuo2000 | 0:f700c61f47e5 | 51 | rgbled_B=0; |
rkuo2000 | 0:f700c61f47e5 | 52 | } |
rkuo2000 | 0:f700c61f47e5 | 53 | else { |
rkuo2000 | 0:f700c61f47e5 | 54 | greenled=1; |
rkuo2000 | 0:f700c61f47e5 | 55 | rgbled_B=1; |
rkuo2000 | 0:f700c61f47e5 | 56 | } |
rkuo2000 | 0:f700c61f47e5 | 57 | // press SW2 will turn on buzzer |
rkuo2000 | 0:f700c61f47e5 | 58 | if (button_SW2==0) buzzer=0; |
rkuo2000 | 0:f700c61f47e5 | 59 | else buzzer=1; |
rkuo2000 | 0:f700c61f47e5 | 60 | } |
rkuo2000 | 0:f700c61f47e5 | 61 | } |
rkuo2000 | 0:f700c61f47e5 | 62 |