Simple training demonstration to show the use of structures
Fork of PointerExample by
main.cpp@1:d9da28105bef, 2013-11-25 (annotated)
- Committer:
- jf1452
- Date:
- Mon Nov 25 14:26:04 2013 +0000
- Revision:
- 1:d9da28105bef
- Parent:
- 0:7dec7e9ac085
- Child:
- 2:db81cad8cb64
Corrected a spelling mistake
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jf1452 | 1:d9da28105bef | 1 | /******************************************************************************* |
jf1452 | 1:d9da28105bef | 2 | * This program demonstrates how to read a switch and toggle a LED. * |
jf1452 | 1:d9da28105bef | 3 | * Connect LED and resistor between to DIP36 (P0_21) and DIP1 (0V). * |
jf1452 | 1:d9da28105bef | 4 | * Connect switch between DIP5 (P0_9) and DIP1 (0V). * |
jf1452 | 1:d9da28105bef | 5 | * * |
jf1452 | 1:d9da28105bef | 6 | * Jon Fuge * |
jf1452 | 1:d9da28105bef | 7 | * V1.0 12/11/2013 First issue of code * |
jf1452 | 1:d9da28105bef | 8 | *******************************************************************************/ |
dan | 0:7dec7e9ac085 | 9 | |
jf1452 | 1:d9da28105bef | 10 | #include "mbed.h" // has prototypes for DigitalIn and DigitalOut |
jf1452 | 1:d9da28105bef | 11 | |
jf1452 | 1:d9da28105bef | 12 | DigitalIn mybutton(P0_9); // mybutton reads bit 9 of port 0 (DIP5). |
jf1452 | 1:d9da28105bef | 13 | DigitalOut myled(P0_21); // myled controls bit 21 of port 0 (DIP36). |
dan | 0:7dec7e9ac085 | 14 | |
dan | 0:7dec7e9ac085 | 15 | int main() { |
jf1452 | 1:d9da28105bef | 16 | mybutton.mode(PullUp); // Configure pin to be a pull‐up input |
jf1452 | 1:d9da28105bef | 17 | for(;;) { //Create infinite loop to keep program running. |
jf1452 | 1:d9da28105bef | 18 | if (mybutton == 0) { // if mybutton = 0, then it has been pressed |
jf1452 | 1:d9da28105bef | 19 | myled = !myled; // myled will now become !myled (! means NOT). |
jf1452 | 1:d9da28105bef | 20 | wait(0.1); // Wait for 0.1 seconds to "debounce" the switch. |
jf1452 | 1:d9da28105bef | 21 | while (mybutton == 0) {} // Wait for my button to be released. |
jf1452 | 1:d9da28105bef | 22 | } // End of if (mybutton == 0) |
jf1452 | 1:d9da28105bef | 23 | } // End of for(;;) |
jf1452 | 1:d9da28105bef | 24 | } // end of int main() |