Nuvoton
/
NuMaker-mbed-GPIO-button-buzzer-rgbled
NuMaker GPIO button with LED and buzzer
main.cpp@9:19b2945fefd4, 2017-10-17 (annotated)
- Committer:
- ccchang
- Date:
- Tue Oct 17 13:52:48 2017 +0800
- Revision:
- 9:19b2945fefd4
- Parent:
- 8:876e8a140f39
- Child:
- 11:9a0562f4e236
Support NANO130
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 |
ccchang |
9:19b2945fefd4 | 27 | #elif defined(TARGET_NUMAKER_PFM_NANO130) |
ccchang |
9:19b2945fefd4 | 28 | DigitalOut rgbled_B(PE_10); // in NANO130 rgbled_B is yellow, not blue. low-active |
ccchang |
9:19b2945fefd4 | 29 | DigitalOut rgbled_R(PE_9); // low-active |
ccchang |
9:19b2945fefd4 | 30 | DigitalOut rgbled_G(PE_11); // low-active |
ccchang |
9:19b2945fefd4 | 31 | DigitalOut greenled(PE_11); // in NANO130 use the pin to connect the led, low-active |
ccchang |
9:19b2945fefd4 | 32 | DigitalOut buzzer(PA_13); // in NANO130 use the pin to connect the buzzer, low-active |
ccchang |
9:19b2945fefd4 | 33 | DigitalIn button_SW1(PE_5); // in NANO130 button_SW1 is SW2, press button =0 |
ccchang |
9:19b2945fefd4 | 34 | DigitalIn button_SW2(PE_6); // in NANO130 button_SW2 is SW3, 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; |
rkuo2000 | 0:f700c61f47e5 | 44 | |
rkuo2000 | 0:f700c61f47e5 | 45 | while (true) { |
rkuo2000 | 0:f700c61f47e5 | 46 | // press SW1 will turn on greeled and RGBLED=blue |
rkuo2000 | 0:f700c61f47e5 | 47 | if (button_SW1==0) { |
rkuo2000 | 0:f700c61f47e5 | 48 | greenled=0; |
rkuo2000 | 0:f700c61f47e5 | 49 | rgbled_B=0; |
rkuo2000 | 0:f700c61f47e5 | 50 | } |
rkuo2000 | 0:f700c61f47e5 | 51 | else { |
rkuo2000 | 0:f700c61f47e5 | 52 | greenled=1; |
rkuo2000 | 0:f700c61f47e5 | 53 | rgbled_B=1; |
rkuo2000 | 0:f700c61f47e5 | 54 | } |
rkuo2000 | 0:f700c61f47e5 | 55 | // press SW2 will turn on buzzer |
rkuo2000 | 0:f700c61f47e5 | 56 | if (button_SW2==0) buzzer=0; |
rkuo2000 | 0:f700c61f47e5 | 57 | else buzzer=1; |
rkuo2000 | 0:f700c61f47e5 | 58 | } |
rkuo2000 | 0:f700c61f47e5 | 59 | } |
rkuo2000 | 0:f700c61f47e5 | 60 |