Factory Monitor

Dependencies:   mbed

factory sense HQ

Committer:
Nick123
Date:
Tue Aug 25 13:34:41 2015 +0000
Revision:
5:faa8843f3990
Parent:
4:7a50e0818a47
Child:
6:e8819487b352
so it says my expression has no effect, I think i have missunderstood something

Who changed what in which revision?

UserRevisionLine numberNew contents of line
melmon 0:a521da10b15a 1 #include "mbed.h"
melmon 0:a521da10b15a 2
melmon 4:7a50e0818a47 3 #define no_pins 2
Nick123 5:faa8843f3990 4 #define Inputs 0
Nick123 5:faa8843f3990 5 #define Outputs 1
melmon 4:7a50e0818a47 6 #define Rejects Values[2]
melmon 4:7a50e0818a47 7
melmon 4:7a50e0818a47 8
melmon 0:a521da10b15a 9 DigitalIn sensorPin1(p5);
Nick123 1:b52588ac9aae 10 DigitalIn sensorPin2(p6);
Nick123 1:b52588ac9aae 11 //variables
melmon 0:a521da10b15a 12
melmon 0:a521da10b15a 13 // initialize serial communication:
melmon 0:a521da10b15a 14 Serial pc(USBTX, USBRX);
melmon 0:a521da10b15a 15
Nick123 2:cff64a27ae9d 16 class PinCheck {
melmon 3:cff56a809a37 17
Nick123 2:cff64a27ae9d 18 public:
Nick123 2:cff64a27ae9d 19 PinCheck(PinName pin) : _pin(pin) {
melmon 3:cff56a809a37 20
Nick123 2:cff64a27ae9d 21 }
Nick123 2:cff64a27ae9d 22
Nick123 2:cff64a27ae9d 23
melmon 4:7a50e0818a47 24 int Go_and_check(int a) {
melmon 3:cff56a809a37 25 sensorState = _pin; // read the sensor input pin:
melmon 4:7a50e0818a47 26 int zero = 0;
melmon 4:7a50e0818a47 27 if (sensorState != lastSensorState[a]) // compare the sensorState to its previous state
melmon 0:a521da10b15a 28 {
melmon 0:a521da10b15a 29 // if the state has changed, check to see if it is a change from high to low or low to high
melmon 3:cff56a809a37 30 if (sensorState == 1){ // if the current state is HIGH then increment the counter
Nick123 5:faa8843f3990 31 if (a == Inputs){ lastSensorState[a] == sensorState;}
Nick123 5:faa8843f3990 32 if (a == Outputs){ lastSensorState[a] == sensorState;}
melmon 3:cff56a809a37 33 return sensorState;
melmon 0:a521da10b15a 34 }
melmon 0:a521da10b15a 35
Nick123 5:faa8843f3990 36 else { // if the current state is LOW then ignore
Nick123 5:faa8843f3990 37 if (a == Inputs){ lastSensorState[a] == sensorState;}
Nick123 5:faa8843f3990 38 if (a == Outputs){ lastSensorState[a] == sensorState;}
melmon 4:7a50e0818a47 39 return zero;
melmon 0:a521da10b15a 40 }
melmon 0:a521da10b15a 41 }
melmon 4:7a50e0818a47 42 return zero;
Nick123 1:b52588ac9aae 43 }
melmon 3:cff56a809a37 44
Nick123 2:cff64a27ae9d 45 private:
Nick123 2:cff64a27ae9d 46 DigitalIn _pin;
melmon 4:7a50e0818a47 47 int sensorState;
melmon 4:7a50e0818a47 48 int lastSensorState[no_pins];
melmon 4:7a50e0818a47 49
melmon 3:cff56a809a37 50
Nick123 2:cff64a27ae9d 51 };
Nick123 2:cff64a27ae9d 52
melmon 4:7a50e0818a47 53 PinCheck inputs(p6);
melmon 4:7a50e0818a47 54 PinCheck outputs(p5);
Nick123 1:b52588ac9aae 55
Nick123 1:b52588ac9aae 56 int main() {
melmon 4:7a50e0818a47 57
Nick123 5:faa8843f3990 58 int Values[3];
Nick123 5:faa8843f3990 59
Nick123 1:b52588ac9aae 60
Nick123 1:b52588ac9aae 61 while(1)
Nick123 1:b52588ac9aae 62 {
melmon 4:7a50e0818a47 63
melmon 4:7a50e0818a47 64 for(int i = 0; i < no_pins; i ++){
melmon 4:7a50e0818a47 65 if (i == Inputs){ Values[i] += inputs.Go_and_check(i); }
melmon 4:7a50e0818a47 66 if (i == Outputs){ Values[i] += outputs.Go_and_check(i); }
melmon 4:7a50e0818a47 67
melmon 4:7a50e0818a47 68 };
Nick123 1:b52588ac9aae 69
melmon 0:a521da10b15a 70 }
melmon 0:a521da10b15a 71 }