Gas-Sense
/
Factory_monitor_0v1
a wee bit of code
Revision 0:1cc57e14d42f, committed 2015-07-29
- Comitter:
- Nick123
- Date:
- Wed Jul 29 21:00:51 2015 +0000
- Commit message:
- initial commit
Changed in this revision
diff -r 000000000000 -r 1cc57e14d42f Arduino.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Arduino.lib Wed Jul 29 21:00:51 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/TheChrisyd/code/Arduino/#272d0276d474
diff -r 000000000000 -r 1cc57e14d42f main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jul 29 21:00:51 2015 +0000 @@ -0,0 +1,46 @@ +#include "mbed.h" +#include "arduino.h" +using namespace std; +DigitalOut myled(LED1); + +// constants: +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); +Serial.baud(9600); + +int main() +{ + while(1) + { + // read the pushbutton input pin: + sensorState1 = digitalRead(sensorPin1); + // compare the buttonState to its previous state + if (sensorState1 != lastSensorState1) + { + // if the state has changed, check to see if it is a change from high to low or low to high + if (sensorState1 == HIGH) + { + // if the current state is HIGH then increment the counter + counter++; + Serial.println(counter); + } + else + { + // if the current state is LOW then the button + Serial.println(counter); + } + } + // save the current state as the last state, + //for next time through the loop + lastSensorState1 = sensorState1; + //pause to aviod spikes delay(20); + } +} \ No newline at end of file
diff -r 000000000000 -r 1cc57e14d42f mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jul 29 21:00:51 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/da0ca467f8b5 \ No newline at end of file