Factory Monitor

Dependencies:   mbed

factory sense HQ

Revision:
4:7a50e0818a47
Parent:
3:cff56a809a37
Child:
5:faa8843f3990
diff -r cff56a809a37 -r 7a50e0818a47 main.cpp
--- a/main.cpp	Sat Aug 15 12:18:07 2015 +0000
+++ b/main.cpp	Sat Aug 15 12:47:10 2015 +0000
@@ -1,5 +1,11 @@
 #include "mbed.h"
 
+#define no_pins 2
+#define Inputs Values[0]
+#define Outputs Values[1]
+#define Rejects Values[2]
+
+
 DigitalIn sensorPin1(p5);
 DigitalIn sensorPin2(p6);
     //variables
@@ -15,10 +21,10 @@
     }
 
 
-bool Go_and_check() {
+int Go_and_check(int a) {
     sensorState = _pin; // read the sensor input pin:   
-                 
-        if (sensorState != lastSensorState) // compare the sensorState to its previous state
+    int zero = 0;            
+        if (sensorState != lastSensorState[a]) // compare the sensorState to its previous state
         {
             // if the state has changed, check to see if it is a change from high to low or low to high             
             if (sensorState == 1){ // if the current state is HIGH then increment the counter
@@ -26,31 +32,35 @@
             }
             
             else { // if the current state is LOW then ignore      
-                return sensorState;
+                return zero;
             }
         }
-        lastSensorState = sensorState;
+        return zero;
 }
 
 private:
     DigitalIn _pin;
-    bool sensorState;
-    bool lastSensorState;
+    int sensorState;
+    int lastSensorState[no_pins];
+    
     
 };
 
+PinCheck inputs(p6);
+PinCheck outputs(p5);
 
 int main() {
-    // variables:   
-int outputs = 0; // counter for the number of products passing through 
-int inputs = 0; //counter for the number of products entering station
-int rejects = 0; //counter for products ejected from lines between stations
+     
+    int Values[3]; // counter for the number of products passing through 
 
     while(1)
     {
-        outputs += sensorPin1.Go_and_check();
-        inputs += sensorPin2.Go_and_check();
-        rejects = previous_outputs - inputs;
+        
+        for(int i = 0; i < no_pins; i ++){
+            if (i == Inputs){ Values[i] += inputs.Go_and_check(i); }
+            if (i == Outputs){ Values[i] += outputs.Go_and_check(i); }
+            
+        };
         
     }
 }