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
main.cpp@7:73a722360cdb, 2014-06-21 (annotated)
- Committer:
- mfillinois
- Date:
- Sat Jun 21 20:14:09 2014 +0000
- Revision:
- 7:73a722360cdb
- Parent:
- 6:f2c616fa9ffe
- Child:
- 8:f81057354da4
Sends data over bluetooth after a run
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmcohen24 | 0:1802ead3667e | 1 | #include "mbed.h" |
dmcohen24 | 0:1802ead3667e | 2 | #include "SI1143.h" |
mfillinois | 5:b77b678ed22f | 3 | #include "m3pi.h" |
mfillinois | 7:73a722360cdb | 4 | #define NN 1000 |
dmcohen24 | 0:1802ead3667e | 5 | |
dmcohen24 | 3:0359b918f658 | 6 | //DigitalOut enable(p30); |
mfillinois | 5:b77b678ed22f | 7 | //Ticker timer; |
dmcohen24 | 3:0359b918f658 | 8 | |
dmcohen24 | 3:0359b918f658 | 9 | I2C* i2c = new I2C(p28, p27); |
mfillinois | 5:b77b678ed22f | 10 | Serial bt(p13, p14); |
mfillinois | 5:b77b678ed22f | 11 | m3pi pi; |
dmcohen24 | 0:1802ead3667e | 12 | |
mfillinois | 6:f2c616fa9ffe | 13 | DigitalOut led1(LED1); |
mfillinois | 6:f2c616fa9ffe | 14 | DigitalOut led2(LED2); |
mfillinois | 6:f2c616fa9ffe | 15 | DigitalOut led3(LED3); |
mfillinois | 6:f2c616fa9ffe | 16 | DigitalOut led4(LED4); |
dmcohen24 | 0:1802ead3667e | 17 | |
mfillinois | 5:b77b678ed22f | 18 | InterruptIn event(p26); |
dmcohen24 | 3:0359b918f658 | 19 | |
dmcohen24 | 3:0359b918f658 | 20 | SI1143 sensor1(i2c, p30, p29, 0x01); |
mfillinois | 5:b77b678ed22f | 21 | //SI1143 sensor2(i2c, p25, p26, 0x02); // p25, p26 |
dmcohen24 | 3:0359b918f658 | 22 | |
dmcohen24 | 3:0359b918f658 | 23 | //InterruptIn prox_meas(p26); //26 |
dmcohen24 | 3:0359b918f658 | 24 | int sense1a, sense1b, sense2a, sense2b; |
mfillinois | 7:73a722360cdb | 25 | int sensor1alog[NN]; |
mfillinois | 7:73a722360cdb | 26 | int sensor1blog[NN]; |
mfillinois | 6:f2c616fa9ffe | 27 | int whileflag = 1; |
mfillinois | 5:b77b678ed22f | 28 | int countingstuffpoop = 0; |
mfillinois | 5:b77b678ed22f | 29 | |
mfillinois | 5:b77b678ed22f | 30 | void meas_int() |
mfillinois | 5:b77b678ed22f | 31 | { |
dmcohen24 | 2:8798491332ed | 32 | led1 = 1; |
mfillinois | 5:b77b678ed22f | 33 | sense1a = sensor1.read_ps1(); |
mfillinois | 5:b77b678ed22f | 34 | sense1b = sensor1.read_ps2(); |
mfillinois | 5:b77b678ed22f | 35 | //sense2a = sensor2.get_ps1(1); |
mfillinois | 5:b77b678ed22f | 36 | //sense2b = sensor2.get_ps2(1); |
mfillinois | 6:f2c616fa9ffe | 37 | |
mfillinois | 5:b77b678ed22f | 38 | countingstuffpoop++; |
mfillinois | 7:73a722360cdb | 39 | if(countingstuffpoop < NN) |
mfillinois | 5:b77b678ed22f | 40 | { |
mfillinois | 5:b77b678ed22f | 41 | led4 = 0; |
mfillinois | 6:f2c616fa9ffe | 42 | sensor1alog[countingstuffpoop-1] = sense1a; |
mfillinois | 6:f2c616fa9ffe | 43 | sensor1blog[countingstuffpoop-1] = sense1b; |
mfillinois | 5:b77b678ed22f | 44 | } |
mfillinois | 6:f2c616fa9ffe | 45 | else |
mfillinois | 6:f2c616fa9ffe | 46 | { |
mfillinois | 6:f2c616fa9ffe | 47 | __disable_irq(); |
mfillinois | 6:f2c616fa9ffe | 48 | whileflag = 0; |
mfillinois | 7:73a722360cdb | 49 | led4 = 1; |
mfillinois | 6:f2c616fa9ffe | 50 | } |
mfillinois | 6:f2c616fa9ffe | 51 | |
mfillinois | 5:b77b678ed22f | 52 | sensor1.clear_int(); |
dmcohen24 | 3:0359b918f658 | 53 | led1 = 0; |
dmcohen24 | 2:8798491332ed | 54 | } |
dmcohen24 | 2:8798491332ed | 55 | |
mfillinois | 7:73a722360cdb | 56 | void blinkblink(int t, int n) |
mfillinois | 7:73a722360cdb | 57 | { |
mfillinois | 7:73a722360cdb | 58 | for (int i = 1; i <= n; i++) |
mfillinois | 7:73a722360cdb | 59 | { |
mfillinois | 7:73a722360cdb | 60 | led4 = 1; |
mfillinois | 7:73a722360cdb | 61 | wait(t); |
mfillinois | 7:73a722360cdb | 62 | led4 = 0; |
mfillinois | 7:73a722360cdb | 63 | wait(t); |
mfillinois | 7:73a722360cdb | 64 | } |
mfillinois | 7:73a722360cdb | 65 | } |
mfillinois | 7:73a722360cdb | 66 | |
dmcohen24 | 0:1802ead3667e | 67 | int main() |
mfillinois | 6:f2c616fa9ffe | 68 | { |
dmcohen24 | 3:0359b918f658 | 69 | led2 = 0; |
mfillinois | 7:73a722360cdb | 70 | //wait(10); |
mfillinois | 7:73a722360cdb | 71 | blinkblink(1,2); |
mfillinois | 6:f2c616fa9ffe | 72 | |
mfillinois | 5:b77b678ed22f | 73 | event.fall(&meas_int); |
mfillinois | 5:b77b678ed22f | 74 | //timer.attach(&meas_int, 0.01); |
mfillinois | 5:b77b678ed22f | 75 | sensor1.start_ps_auto(); |
mfillinois | 5:b77b678ed22f | 76 | led4 = 1; |
mfillinois | 7:73a722360cdb | 77 | //pi.left(0.1); |
dmcohen24 | 3:0359b918f658 | 78 | |
mfillinois | 6:f2c616fa9ffe | 79 | while(whileflag) |
dmcohen24 | 0:1802ead3667e | 80 | { |
dmcohen24 | 0:1802ead3667e | 81 | // Read each led sensor |
mfillinois | 7:73a722360cdb | 82 | led2 = whileflag; |
dmcohen24 | 0:1802ead3667e | 83 | } |
mfillinois | 7:73a722360cdb | 84 | led3 = 0; |
mfillinois | 7:73a722360cdb | 85 | //pi.stop(); |
mfillinois | 7:73a722360cdb | 86 | blinkblink(1,5); |
mfillinois | 6:f2c616fa9ffe | 87 | |
mfillinois | 7:73a722360cdb | 88 | |
mfillinois | 6:f2c616fa9ffe | 89 | bt.printf("d = ["); |
mfillinois | 7:73a722360cdb | 90 | for (int i = 0; i < NN; i++) |
mfillinois | 6:f2c616fa9ffe | 91 | { |
mfillinois | 6:f2c616fa9ffe | 92 | bt.printf("%d, %d;\r\n", sensor1alog[i], sensor1blog[i]); |
mfillinois | 6:f2c616fa9ffe | 93 | //bt.printf("%d;\r\n", sensorlog[i]); |
mfillinois | 6:f2c616fa9ffe | 94 | } |
mfillinois | 6:f2c616fa9ffe | 95 | bt.printf("0, 0];"); |
mfillinois | 6:f2c616fa9ffe | 96 | led1 = 1; |
mfillinois | 6:f2c616fa9ffe | 97 | wait(0.3); |
mfillinois | 6:f2c616fa9ffe | 98 | led1 = 0; |
mfillinois | 6:f2c616fa9ffe | 99 | wait(0.3); |
mfillinois | 6:f2c616fa9ffe | 100 | led1 = 1; |
dmcohen24 | 3:0359b918f658 | 101 | } |