
Factory Monitor
Dependencies: mbed
factory sense HQ
Diff: main.cpp
- Revision:
- 3:cff56a809a37
- Parent:
- 2:cff64a27ae9d
- Child:
- 4:7a50e0818a47
--- a/main.cpp Sat Aug 15 11:37:09 2015 +0000 +++ b/main.cpp Sat Aug 15 12:18:07 2015 +0000 @@ -3,39 +3,40 @@ 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: +bool Go_and_check() { + sensorState = _pin; // read the sensor input pin: - if (sensorState(_pin) != lastSensorState(_pin) // compare the sensorState to its previous state + 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(_pin) == 1){ // if the current state is HIGH then increment the counter - return n; + 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 n; + return sensorState; } } - lastSensorState(_pin) = sensorState(_pin); + lastSensorState = sensorState; } + private: DigitalIn _pin; + bool sensorState; + bool lastSensorState; + };