Junichi Katsu
/
PCSerialDitalIn_test
PCシリアルサンプルプログラム mbedセミナー演習2ex
main.cpp@0:c886b74709da, 2011-08-26 (annotated)
- Committer:
- jksoft
- Date:
- Fri Aug 26 15:37:17 2011 +0000
- Revision:
- 0:c886b74709da
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jksoft | 0:c886b74709da | 1 | #include "mbed.h" |
jksoft | 0:c886b74709da | 2 | |
jksoft | 0:c886b74709da | 3 | Serial pc(USBTX, USBRX); // tx, rx |
jksoft | 0:c886b74709da | 4 | DigitalIn sw(p5); |
jksoft | 0:c886b74709da | 5 | |
jksoft | 0:c886b74709da | 6 | int main() { |
jksoft | 0:c886b74709da | 7 | int old = sw; |
jksoft | 0:c886b74709da | 8 | int count = 0; |
jksoft | 0:c886b74709da | 9 | |
jksoft | 0:c886b74709da | 10 | sw.mode(PullUp); |
jksoft | 0:c886b74709da | 11 | |
jksoft | 0:c886b74709da | 12 | pc.printf("Counter!"); |
jksoft | 0:c886b74709da | 13 | |
jksoft | 0:c886b74709da | 14 | while(1) { |
jksoft | 0:c886b74709da | 15 | if((sw == 0)&&(old == 1)) |
jksoft | 0:c886b74709da | 16 | { |
jksoft | 0:c886b74709da | 17 | count++; |
jksoft | 0:c886b74709da | 18 | printf("%d\r\n",count); |
jksoft | 0:c886b74709da | 19 | wait(0.2); |
jksoft | 0:c886b74709da | 20 | } |
jksoft | 0:c886b74709da | 21 | old = sw; |
jksoft | 0:c886b74709da | 22 | } |
jksoft | 0:c886b74709da | 23 | } |