Nuvoton
/
NuMaker-mbed-GPIO-button-buzzer-rgbled
NuMaker GPIO button with LED and buzzer
main.cpp@8:876e8a140f39, 2017-10-02 (annotated)
- Committer:
- shliu1
- Date:
- Mon Oct 02 11:33:59 2017 +0800
- Revision:
- 8:876e8a140f39
- Parent:
- 5:4a573124ab4a
- Child:
- 9:19b2945fefd4
modify main.cpp for M487
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 1:7a0a00da91c7 | 1 | // For NuMaker-PFM-NUC472 GPIO pins connected to rgbled, green led, buzzer |
rkuo2000 | 0:f700c61f47e5 | 2 | #include "mbed.h" |
shliu1 |
5:4a573124ab4a | 3 | #if defined(TARGET_NUMAKER_PFM_NUC472) |
rkuo2000 | 0:f700c61f47e5 | 4 | DigitalOut rgbled_B(PD_8); // low-active |
rkuo2000 | 0:f700c61f47e5 | 5 | DigitalOut rgbled_R(PD_9); // low-active |
rkuo2000 | 0:f700c61f47e5 | 6 | DigitalOut rgbled_G(PA_4); // low-active |
rkuo2000 | 0:f700c61f47e5 | 7 | DigitalOut greenled(PG_0); // low-active |
rkuo2000 | 0:f700c61f47e5 | 8 | DigitalOut buzzer(PD_11); // low-active |
rkuo2000 | 0:f700c61f47e5 | 9 | DigitalIn button_SW1(PC_12); // press button =0 |
rkuo2000 | 0:f700c61f47e5 | 10 | DigitalIn button_SW2(PC_13); // press button =0 |
shliu1 |
5:4a573124ab4a | 11 | #elif defined(TARGET_NUMAKER_PFM_M453) |
shliu1 |
5:4a573124ab4a | 12 | DigitalOut rgbled_B(PD_7); // low-active |
shliu1 |
5:4a573124ab4a | 13 | DigitalOut rgbled_R(PD_2); // low-active |
shliu1 |
5:4a573124ab4a | 14 | DigitalOut rgbled_G(PD_3); // low-active |
shliu1 |
5:4a573124ab4a | 15 | DigitalOut greenled(PB_12); // low-active |
shliu1 |
5:4a573124ab4a | 16 | DigitalOut buzzer(PE_2); // low-active |
shliu1 |
5:4a573124ab4a | 17 | DigitalIn button_SW1(PA_15); // press button =0 |
shliu1 |
5:4a573124ab4a | 18 | DigitalIn button_SW2(PA_14); // press button =0 |
shliu1 |
8:876e8a140f39 | 19 | #elif defined(TARGET_NUMAKER_PFM_M487) |
shliu1 |
8:876e8a140f39 | 20 | DigitalOut rgbled_B(PH_1); // in M487 rgbled_B is yellow, not blue. low-active |
shliu1 |
8:876e8a140f39 | 21 | DigitalOut rgbled_R(PH_0); // low-active |
shliu1 |
8:876e8a140f39 | 22 | DigitalOut rgbled_G(PH_2); // low-active |
shliu1 |
8:876e8a140f39 | 23 | DigitalOut greenled(PH_2); // in M487 use the pin to connect the led, low-active |
shliu1 |
8:876e8a140f39 | 24 | DigitalOut buzzer(PF_11); // in M487 use the pin to connect the buzzer, low-active |
shliu1 |
8:876e8a140f39 | 25 | DigitalIn button_SW1(PC_10); // in M487 button_SW1 is SW2, press button =0 |
shliu1 |
8:876e8a140f39 | 26 | DigitalIn button_SW2(PC_9); // in M487 button_SW2 is SW3, press button =0 |
shliu1 |
5:4a573124ab4a | 27 | #endif |
rkuo2000 | 0:f700c61f47e5 | 28 | |
rkuo2000 | 0:f700c61f47e5 | 29 | // main() runs in its own thread in the OS |
shliu1 |
5:4a573124ab4a | 30 | // (note the calls to Thread::wait below for d elays) |
rkuo2000 | 0:f700c61f47e5 | 31 | int main() { |
rkuo2000 | 0:f700c61f47e5 | 32 | |
rkuo2000 | 0:f700c61f47e5 | 33 | rgbled_B=1; rgbled_R=1; rgbled_G=1; |
rkuo2000 | 0:f700c61f47e5 | 34 | greenled=1; |
rkuo2000 | 0:f700c61f47e5 | 35 | buzzer=1; |
rkuo2000 | 0:f700c61f47e5 | 36 | |
rkuo2000 | 0:f700c61f47e5 | 37 | while (true) { |
rkuo2000 | 0:f700c61f47e5 | 38 | // press SW1 will turn on greeled and RGBLED=blue |
rkuo2000 | 0:f700c61f47e5 | 39 | if (button_SW1==0) { |
rkuo2000 | 0:f700c61f47e5 | 40 | greenled=0; |
rkuo2000 | 0:f700c61f47e5 | 41 | rgbled_B=0; |
rkuo2000 | 0:f700c61f47e5 | 42 | } |
rkuo2000 | 0:f700c61f47e5 | 43 | else { |
rkuo2000 | 0:f700c61f47e5 | 44 | greenled=1; |
rkuo2000 | 0:f700c61f47e5 | 45 | rgbled_B=1; |
rkuo2000 | 0:f700c61f47e5 | 46 | } |
rkuo2000 | 0:f700c61f47e5 | 47 | // press SW2 will turn on buzzer |
rkuo2000 | 0:f700c61f47e5 | 48 | if (button_SW2==0) buzzer=0; |
rkuo2000 | 0:f700c61f47e5 | 49 | else buzzer=1; |
rkuo2000 | 0:f700c61f47e5 | 50 | } |
rkuo2000 | 0:f700c61f47e5 | 51 | } |
rkuo2000 | 0:f700c61f47e5 | 52 |