Factory Monitor

Dependencies:   mbed

factory sense HQ

main.cpp

Committer:
Nick123
Date:
2015-09-03
Revision:
9:3ee4f273d7d6
Parent:
8:e417787cb2fa
Child:
10:0333f8137979

File content as of revision 9:3ee4f273d7d6:

#include "mbed.h"

#define no_pins 2
#define Inputs 0
#define Outputs 0
#define Rejects Values[2]


DigitalIn sensorPin1( p5, PullDown);
DigitalIn sensorPin2( p6, PullDown);
    //variables

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

class PinCheck {

public:
    PinCheck(PinName pin) : _pin(pin) {
    
    }


int Go_and_check(int a) {
    sensorState = _pin; // read the sensor input pin:   
    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
                lastSensorState[a] = sensorState;
                return sensorState;
            }
            
            else { // if the current state is LOW then ignore
                lastSensorState[a] = sensorState;
                return zero;
            }
        }
        return zero;
}

private:
    DigitalIn _pin;
    int sensorState;
    int lastSensorState[no_pins];
    
    
};

PinCheck inputs(p6);
PinCheck outputs(p5);

int main() {
     
    int Values[3]; 


    while(1)
    {
        
        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); }
            
        };
    Rejects = (Inputs - Outputs);
    pc.printf("inputs %d \n",Inputs);
    pc.printf("outputs %d \n",Outputs);
    pc.printf("rejects %d \n",Rejects);
    wait(0.2);    
    }
}