Factory Monitor

Dependencies:   mbed

factory sense HQ

main.cpp

Committer:
Nick123
Date:
2015-08-12
Revision:
1:b52588ac9aae
Parent:
0:a521da10b15a
Child:
2:cff64a27ae9d

File content as of revision 1:b52588ac9aae:

#include "mbed.h"

DigitalIn sensorPin1(p5);
DigitalIn sensorPin2(p6);
DigitalIn sensorPin3(p7);
    //variables
int sensorState1 = 0;    // current state of the sensor   
int lastSensorState1 = 0;  // previous state of the sensor 
int sensorState2 = 0;
int lastSensorState2 = 0;
int sensorState3 = 0;
int lastSensorState3 = 0;

// initialize serial communication:   
Serial pc(USBTX, USBRX);

void Go_and_check(sensorPin(n)) {
    sensorState(n) = sensorPin(n); // read the sensor input pin:   
                 
        if (sensorState(n) != lastSensorState(n) // 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(n) == 1){ // if the current state is HIGH then increment the counter
                return 1;
            }
            
            else { // if the current state is LOW then ignore      
                return 0;
            }
        }
        lastSensorState(n) = sensorState(n);
}

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

    while(1)
    {
        outputs += Go_and_check(sensorPin1);
        inputs += Go_and_check(sensorPin2);
        rejects = previous_outputs - inputs;
        
    }
}