Factory Monitor
Dependencies: mbed
factory sense HQ
main.cpp
- Committer:
- melmon
- Date:
- 2015-08-15
- Revision:
- 3:cff56a809a37
- Parent:
- 2:cff64a27ae9d
- Child:
- 4:7a50e0818a47
File content as of revision 3:cff56a809a37:
#include "mbed.h" DigitalIn sensorPin1(p5); DigitalIn sensorPin2(p6); //variables // initialize serial communication: Serial pc(USBTX, USBRX); class PinCheck { public: PinCheck(PinName pin) : _pin(pin) { } bool Go_and_check() { sensorState = _pin; // read the sensor input pin: if (sensorState != lastSensorState) // 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 return sensorState; } else { // if the current state is LOW then ignore return sensorState; } } lastSensorState = sensorState; } private: DigitalIn _pin; bool sensorState; bool lastSensorState; }; 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; } }