Count patients as the enter a waiting room.

Dependencies:   mbed

Fork of ForLoopIteration by Charles Tritt

Files at this revision

API Documentation at this revision

Comitter:
CSTritt
Date:
Tue Oct 17 15:26:16 2017 +0000
Parent:
0:9475544275a6
Commit message:
Initial Version. Working.

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Sep 21 20:11:08 2017 +0000
+++ b/main.cpp	Tue Oct 17 15:26:16 2017 +0000
@@ -1,45 +1,55 @@
 /*
-  Project: ForLoopIteration
+  Project: PatientCounterMain
   File: main.cpp
  
- Demonstrates the use of a for() loop. Lights multiple LEDs in sequence, then
- in reverse.
+ Counts patients entering a leaving a waiting room. This version uses fuctions 
+ that would otherwise be linked to interrupts. 
  
  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);
+
+DigitalIn entered(D12, PullUp);
+DigitalIn left(D13, PullUp);
+
+int count = 0;
+
+void countUp(void) {
+    count++;
+    printf("Counting up: %d.\n", count);
+}
+
+void countDown(void) {
+    if (count > 0) count--;
+    printf("Counting up: %d.\n", count);
+}
  
 int main() {
-  
     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
+        if (!entered) { // Account for entries.
+            while (!entered); // Wait for button release.
+            countUp();
         }
-
-        // 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
+        if (!left) {  // Account for departures.
+            while (!left); // Wait for button release.
+            countDown();
         }
+        // Send count to console.
+        printf("Count: %d, Entered: %d, Left: %d.\n", count, (int) entered, 
+            (int) left);
+        bar_graph = count; // Show count on bar.
+        wait(0.05); // Pause.
     }
 }
\ No newline at end of file