NuMaker GPIO button with LED and buzzer

Committer:
rkuo2000
Date:
Thu Oct 13 10:39:25 2016 +0000
Revision:
0:f700c61f47e5
Child:
1:7a0a00da91c7
GPIO : SW1 & SW2 input to control LED, RGBLED, Buzzer output

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rkuo2000 0:f700c61f47e5 1 #include "mbed.h"
rkuo2000 0:f700c61f47e5 2
rkuo2000 0:f700c61f47e5 3 DigitalOut rgbled_B(PD_8); // low-active
rkuo2000 0:f700c61f47e5 4 DigitalOut rgbled_R(PD_9); // low-active
rkuo2000 0:f700c61f47e5 5 DigitalOut rgbled_G(PA_4); // low-active
rkuo2000 0:f700c61f47e5 6 DigitalOut greenled(PG_0); // low-active
rkuo2000 0:f700c61f47e5 7 DigitalOut buzzer(PD_11); // low-active
rkuo2000 0:f700c61f47e5 8 DigitalIn button_SW1(PC_12); // press button =0
rkuo2000 0:f700c61f47e5 9 DigitalIn button_SW2(PC_13); // press button =0
rkuo2000 0:f700c61f47e5 10
rkuo2000 0:f700c61f47e5 11 // main() runs in its own thread in the OS
rkuo2000 0:f700c61f47e5 12 // (note the calls to Thread::wait below for delays)
rkuo2000 0:f700c61f47e5 13 int main() {
rkuo2000 0:f700c61f47e5 14
rkuo2000 0:f700c61f47e5 15 rgbled_B=1; rgbled_R=1; rgbled_G=1;
rkuo2000 0:f700c61f47e5 16 greenled=1;
rkuo2000 0:f700c61f47e5 17 buzzer=1;
rkuo2000 0:f700c61f47e5 18
rkuo2000 0:f700c61f47e5 19 while (true) {
rkuo2000 0:f700c61f47e5 20 // press SW1 will turn on greeled and RGBLED=blue
rkuo2000 0:f700c61f47e5 21 if (button_SW1==0) {
rkuo2000 0:f700c61f47e5 22 greenled=0;
rkuo2000 0:f700c61f47e5 23 rgbled_B=0;
rkuo2000 0:f700c61f47e5 24 }
rkuo2000 0:f700c61f47e5 25 else {
rkuo2000 0:f700c61f47e5 26 greenled=1;
rkuo2000 0:f700c61f47e5 27 rgbled_B=1;
rkuo2000 0:f700c61f47e5 28 }
rkuo2000 0:f700c61f47e5 29 // press SW2 will turn on buzzer
rkuo2000 0:f700c61f47e5 30 if (button_SW2==0) buzzer=0;
rkuo2000 0:f700c61f47e5 31 else buzzer=1;
rkuo2000 0:f700c61f47e5 32 }
rkuo2000 0:f700c61f47e5 33 }
rkuo2000 0:f700c61f47e5 34