Factory Monitor

Dependencies:   mbed

factory sense HQ

Committer:
melmon
Date:
Wed Jul 29 21:17:14 2015 +0000
Revision:
0:a521da10b15a
Child:
1:b52588ac9aae
Fixed initial arduino porting issues. Now ready for multiple inputs and proper counting mechanism.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
melmon 0:a521da10b15a 1 #include "mbed.h"
melmon 0:a521da10b15a 2
melmon 0:a521da10b15a 3
melmon 0:a521da10b15a 4 DigitalIn sensorPin1(p5);
melmon 0:a521da10b15a 5 // variables:
melmon 0:a521da10b15a 6 int counter = 0; // counter for the number of products passing through
melmon 0:a521da10b15a 7 int sensorState1 = 0; // current state of the sensor
melmon 0:a521da10b15a 8 int lastSensorState1 = 0; // previous state of the sensor
melmon 0:a521da10b15a 9
melmon 0:a521da10b15a 10 // initialize serial communication:
melmon 0:a521da10b15a 11 Serial pc(USBTX, USBRX);
melmon 0:a521da10b15a 12
melmon 0:a521da10b15a 13 DigitalOut myled(LED1);
melmon 0:a521da10b15a 14
melmon 0:a521da10b15a 15
melmon 0:a521da10b15a 16
melmon 0:a521da10b15a 17 int main() {
melmon 0:a521da10b15a 18 while(1)
melmon 0:a521da10b15a 19 {
melmon 0:a521da10b15a 20 sensorState1 = sensorPin1; // read the pushbutton input pin:
melmon 0:a521da10b15a 21
melmon 0:a521da10b15a 22 if (sensorState1 != lastSensorState1) // compare the buttonState to its previous state
melmon 0:a521da10b15a 23 {
melmon 0:a521da10b15a 24 // if the state has changed, check to see if it is a change from high to low or low to high
melmon 0:a521da10b15a 25 if (sensorState1 == 1){ // if the current state is HIGH then increment the counter
melmon 0:a521da10b15a 26 counter++;
melmon 0:a521da10b15a 27 pc.printf("%f",counter);
melmon 0:a521da10b15a 28 }
melmon 0:a521da10b15a 29
melmon 0:a521da10b15a 30 else { // if the current state is LOW then the button
melmon 0:a521da10b15a 31 pc.printf("%f",counter);
melmon 0:a521da10b15a 32 }
melmon 0:a521da10b15a 33 }
melmon 0:a521da10b15a 34 lastSensorState1 = sensorState1;
melmon 0:a521da10b15a 35 }
melmon 0:a521da10b15a 36 }