Factory Monitor
Dependencies: mbed
factory sense HQ
Diff: main.cpp
- Revision:
- 2:cff64a27ae9d
- Parent:
- 1:b52588ac9aae
- Child:
- 3:cff56a809a37
--- a/main.cpp Wed Aug 12 14:15:29 2015 +0000 +++ b/main.cpp Sat Aug 15 11:37:09 2015 +0000 @@ -2,34 +2,42 @@ 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: +class PinCheck { +public: + PinCheck(PinName pin) : _pin(pin) { + + } + + +void Go_and_check() { + sensorState(_pin) = sensorPin(_pin); // read the sensor input pin: - if (sensorState(n) != lastSensorState(n) // compare the sensorState to its previous state + 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(n) == 1){ // if the current state is HIGH then increment the counter - return 1; + 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 0; + return n; } } - lastSensorState(n) = sensorState(n); + lastSensorState(_pin) = sensorState(_pin); } +private: + DigitalIn _pin; +}; + int main() { // variables: @@ -39,10 +47,9 @@ while(1) { - outputs += Go_and_check(sensorPin1); - inputs += Go_and_check(sensorPin2); + outputs += sensorPin1.Go_and_check(); + inputs += sensorPin2.Go_and_check(); rejects = previous_outputs - inputs; } } -