jim hamblen
/
Pushbutton_NoBounce_Demo
Pushbutton counter demo with debounce
Revision 0:ca31694551ed, committed 2011-09-20
- Comitter:
- 4180_1
- Date:
- Tue Sep 20 14:03:10 2011 +0000
- Commit message:
Changed in this revision
diff -r 000000000000 -r ca31694551ed DebounceIn.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DebounceIn.lib Tue Sep 20 14:03:10 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/AjK/code/DebounceIn/#91a2e988ba9d
diff -r 000000000000 -r ca31694551ed main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Sep 20 14:03:10 2011 +0000 @@ -0,0 +1,35 @@ +#include "mbed.h" +#include "DebounceIn.h" +// must import Cookbook Debounce library into project +// URL: http://mbed.org/users/AjK/libraries/DebounceIn/lky9pc + +DigitalOut myled(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); + +DebounceIn pb(p8); +// SPST Pushbutton count demo using internal PullUp function +// no external PullUp resistor needed +// Pushbutton from P8 to GND. +// Demonstrates need for debounce - will not count more than once per button hit +// This ocuurs on all switches due to mechanical contact bounce +int main() +{ +int count=0; +int old_pb=0; +int new_pb; + // Use internal pullup for pushbutton + pb.mode(PullUp); + // Delay for initial pullup to take effect + wait(.001); + while(1) { + new_pb = pb; + if ((new_pb==0) && (old_pb==1)) count++; + myled4 = count & 0x01; + myled3 = (count & 0x02)>>1; + myled2 = (count & 0x04)>>2; + myled = (count & 0x08)>>3; + old_pb = new_pb; + } +} \ No newline at end of file
diff -r 000000000000 -r ca31694551ed mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Sep 20 14:03:10 2011 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63bcd7ba4912