Count patients as they enter and leave a waiting room. Not working due to button bounce.
Fork of ForLoopIteration by
Revision 1:0dc1ade9379d, committed 2017-10-17
- Comitter:
- CSTritt
- Date:
- Tue Oct 17 15:28:01 2017 +0000
- Parent:
- 0:9475544275a6
- Commit message:
- Initial version. Not working.
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9475544275a6 -r 0dc1ade9379d main.cpp --- a/main.cpp Thu Sep 21 20:11:08 2017 +0000 +++ b/main.cpp Tue Oct 17 15:28:01 2017 +0000 @@ -1,45 +1,49 @@ /* - Project: ForLoopIteration + Project: PatientCounterIntrp File: main.cpp - Demonstrates the use of a for() loop. Lights multiple LEDs in sequence, then - in reverse. + Demonstrates the use of interupts to count patients entering a leaving a + waiting room. However, button bounce appears to make this approach leads to + bounce. The circuit: Bargraph LEDs from pins 2 through 11 to ground via 330 Ohm resistors. + Pushbuttons between pins D14 & 15 and ground (internal pullup resistors + used. - Created 2006 - by David A. Mellis - Modified 30 Aug 2011 - by Tom Igoe - Modified for Nucleo / mbed 12 Aug 2017 - by Sheila Ross - Modified by C. S. Tritt 9/21/17 (v. 1.0) + Created by C. S. Tritt 9/21/17 (v. 1.0) This example code is in the public domain. */ #include "mbed.h" -float delay = 0.1; // Seconds, the higher the number, the slower the rate. - BusOut bar_graph(D2,D3,D4,D5,D6,D7,D8,D9,D10,D11); + +InterruptIn inSensor(D12); +InterruptIn outSensor(D13); + +int count = 0; + +void countUp(void) { + count++; +} + +void countDown(void) { + if (count > 0) count--; +} int main() { - + + inSensor.fall(&countUp); + outSensor.fall(&countDown); + while(true) { // Keep the lights going back and forth forever. - // Lighted bar will shift from 0 to 9 places. - for(int shift = 0; shift < 10; shift++) { - bar_graph = (1<<shift); // A 1 shifted over "shift" places. - wait(delay); // Pause - } - - // Now shift down from 9 to 0 places. - for(int shift = 9; shift >= 0; shift--) { - bar_graph = (1 << shift); // A 1 shifted over "shift" places. - wait(delay); // Pause - } + bar_graph = count; // Show count on bar. + // Send count to console. + printf("Count: %d.\n", count); + wait(0.5); // Pause. } } \ No newline at end of file