Dectection take 1. Fixed adaptation step. Detect based on a number of standard deviations away from the mean.
Dependencies: SI1143 m3pi mbed
Fork of Proximity_Sensor_2_detect by
Diff: main.cpp
- Revision:
- 7:73a722360cdb
- Parent:
- 6:f2c616fa9ffe
- Child:
- 8:f81057354da4
diff -r f2c616fa9ffe -r 73a722360cdb main.cpp --- a/main.cpp Mon Jun 16 15:07:07 2014 +0000 +++ b/main.cpp Sat Jun 21 20:14:09 2014 +0000 @@ -1,10 +1,9 @@ - #include "mbed.h" #include "SI1143.h" #include "m3pi.h" +#define NN 1000 //DigitalOut enable(p30); - //Ticker timer; I2C* i2c = new I2C(p28, p27); @@ -23,12 +22,9 @@ //InterruptIn prox_meas(p26); //26 int sense1a, sense1b, sense2a, sense2b; -//int NN = 500; -int sensor1alog[500]; -int sensor1blog[500]; +int sensor1alog[NN]; +int sensor1blog[NN]; int whileflag = 1; - -//int total = 1000; int countingstuffpoop = 0; void meas_int() @@ -38,11 +34,9 @@ sense1b = sensor1.read_ps2(); //sense2a = sensor2.get_ps1(1); //sense2b = sensor2.get_ps2(1); - //bt.printf("%d, %d;\r\n",sense1a, sense1b); - //wait(0.001); countingstuffpoop++; - if(countingstuffpoop < 500) + if(countingstuffpoop < NN) { led4 = 0; sensor1alog[countingstuffpoop-1] = sense1a; @@ -52,46 +46,48 @@ { __disable_irq(); whileflag = 0; + led4 = 1; } sensor1.clear_int(); led1 = 0; } +void blinkblink(int t, int n) +{ + for (int i = 1; i <= n; i++) + { + led4 = 1; + wait(t); + led4 = 0; + wait(t); + } +} + int main() { - // Setup the baseline - //sensor1.restart(i2c, 0x01); - //printf("%d ",sensor1.adrs); - //sensor2.restart(i2c, 0x02); - //printf("%d\r\n",sensor2.adrs); led2 = 0; - wait(10); + //wait(10); + blinkblink(1,2); event.fall(&meas_int); //timer.attach(&meas_int, 0.01); sensor1.start_ps_auto(); led4 = 1; - pi.left(0.1); + //pi.left(0.1); while(whileflag) { // Read each led sensor - //sense1 = sensor.get_ps1(1); - - //Numeriacl output through terminal - led1 = 0; - led2 = 0; + led2 = whileflag; } + led3 = 0; + //pi.stop(); + blinkblink(1,5); - pi.stop(); - led1 = 1; - wait(0.3); - led1 = 0; - wait(0.3); - led1 = 1; + bt.printf("d = ["); - for (int i = 0; i < 500; i++) + for (int i = 0; i < NN; i++) { bt.printf("%d, %d;\r\n", sensor1alog[i], sensor1blog[i]); //bt.printf("%d;\r\n", sensorlog[i]);