Factory Monitor
Dependencies: mbed
factory sense HQ
Diff: main.cpp
- Revision:
- 0:a521da10b15a
- Child:
- 1:b52588ac9aae
diff -r 000000000000 -r a521da10b15a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 29 21:17:14 2015 +0000 @@ -0,0 +1,36 @@ +#include "mbed.h" + + +DigitalIn sensorPin1(p5); +// variables: +int counter = 0; // counter for the number of products passing through +int sensorState1 = 0; // current state of the sensor +int lastSensorState1 = 0; // previous state of the sensor + +// initialize serial communication: +Serial pc(USBTX, USBRX); + +DigitalOut myled(LED1); + + + +int main() { + while(1) + { + sensorState1 = sensorPin1; // read the pushbutton input pin: + + if (sensorState1 != lastSensorState1) // compare the buttonState 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 (sensorState1 == 1){ // if the current state is HIGH then increment the counter + counter++; + pc.printf("%f",counter); + } + + else { // if the current state is LOW then the button + pc.printf("%f",counter); + } + } + lastSensorState1 = sensorState1; + } +}