![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Factory Monitor
Dependencies: mbed
factory sense HQ
main.cpp
- Committer:
- Nick123
- Date:
- 2015-08-15
- Revision:
- 2:cff64a27ae9d
- Parent:
- 1:b52588ac9aae
- Child:
- 3:cff56a809a37
File content as of revision 2:cff64a27ae9d:
#include "mbed.h" DigitalIn sensorPin1(p5); DigitalIn sensorPin2(p6); //variables int sensorState1 = 0; // current state of the sensor int lastSensorState1 = 0; // previous state of the sensor int sensorState2 = 0; int lastSensorState2 = 0; // initialize serial communication: Serial pc(USBTX, USBRX); class PinCheck { public: PinCheck(PinName pin) : _pin(pin) { } void Go_and_check() { sensorState(_pin) = sensorPin(_pin); // read the sensor input pin: if (sensorState(_pin) != lastSensorState(_pin) // 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(_pin) == 1){ // if the current state is HIGH then increment the counter return n; } else { // if the current state is LOW then ignore return n; } } lastSensorState(_pin) = sensorState(_pin); } private: DigitalIn _pin; }; 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 += sensorPin1.Go_and_check(); inputs += sensorPin2.Go_and_check(); rejects = previous_outputs - inputs; } }