Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:5ea758382ca4, 2016-10-20 (annotated)
- Committer:
- rkuo2000
- Date:
- Thu Oct 20 12:27:12 2016 +0000
- Revision:
- 0:5ea758382ca4
- Child:
- 1:3f1ad029882f
mbed GPIO for Buttons, LEDs, Buzzer
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rkuo2000 | 0:5ea758382ca4 | 1 | // using NuMaker-PFM-NUC472 GPIO pins connected to Buttons, LEDs, Buzzer |
rkuo2000 | 0:5ea758382ca4 | 2 | #include "mbed.h" |
rkuo2000 | 0:5ea758382ca4 | 3 | |
rkuo2000 | 0:5ea758382ca4 | 4 | DigitalOut rgbled_B(PD_8); // low-active |
rkuo2000 | 0:5ea758382ca4 | 5 | DigitalOut rgbled_R(PD_9); // low-active |
rkuo2000 | 0:5ea758382ca4 | 6 | DigitalOut rgbled_G(PA_4); // low-active |
rkuo2000 | 0:5ea758382ca4 | 7 | DigitalOut greenled(PG_0); // low-active |
rkuo2000 | 0:5ea758382ca4 | 8 | DigitalOut buzzer(PD_11); // low-active |
rkuo2000 | 0:5ea758382ca4 | 9 | DigitalIn button_SW1(PC_12); // press button =0 |
rkuo2000 | 0:5ea758382ca4 | 10 | DigitalIn button_SW2(PC_13); // press button =0 |
rkuo2000 | 0:5ea758382ca4 | 11 | |
rkuo2000 | 0:5ea758382ca4 | 12 | // main() runs in its own thread in the OS |
rkuo2000 | 0:5ea758382ca4 | 13 | // (note the calls to Thread::wait below for delays) |
rkuo2000 | 0:5ea758382ca4 | 14 | int main() { |
rkuo2000 | 0:5ea758382ca4 | 15 | |
rkuo2000 | 0:5ea758382ca4 | 16 | rgbled_B=1; rgbled_R=1; rgbled_G=1; |
rkuo2000 | 0:5ea758382ca4 | 17 | greenled=1; |
rkuo2000 | 0:5ea758382ca4 | 18 | buzzer=1; |
rkuo2000 | 0:5ea758382ca4 | 19 | |
rkuo2000 | 0:5ea758382ca4 | 20 | while (true) { |
rkuo2000 | 0:5ea758382ca4 | 21 | // press SW1 will turn on greeled and RGBLED=blue |
rkuo2000 | 0:5ea758382ca4 | 22 | if (button_SW1==0) { |
rkuo2000 | 0:5ea758382ca4 | 23 | greenled=0; |
rkuo2000 | 0:5ea758382ca4 | 24 | rgbled_B=0; |
rkuo2000 | 0:5ea758382ca4 | 25 | } |
rkuo2000 | 0:5ea758382ca4 | 26 | else { |
rkuo2000 | 0:5ea758382ca4 | 27 | greenled=1; |
rkuo2000 | 0:5ea758382ca4 | 28 | rgbled_B=1; |
rkuo2000 | 0:5ea758382ca4 | 29 | } |
rkuo2000 | 0:5ea758382ca4 | 30 | // press SW2 will turn on buzzer |
rkuo2000 | 0:5ea758382ca4 | 31 | if (button_SW2==0) buzzer=0; |
rkuo2000 | 0:5ea758382ca4 | 32 | else buzzer=1; |
rkuo2000 | 0:5ea758382ca4 | 33 | } |
rkuo2000 | 0:5ea758382ca4 | 34 | } |
rkuo2000 | 0:5ea758382ca4 | 35 |