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_sense by
main.cpp@5:b77b678ed22f, 2014-06-12 (annotated)
- Committer:
- mfillinois
- Date:
- Thu Jun 12 20:58:19 2014 +0000
- Revision:
- 5:b77b678ed22f
- Parent:
- 3:0359b918f658
- Child:
- 6:f2c616fa9ffe
sampling experiments
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dmcohen24 | 3:0359b918f658 | 1 | |
dmcohen24 | 0:1802ead3667e | 2 | #include "mbed.h" |
dmcohen24 | 0:1802ead3667e | 3 | #include "SI1143.h" |
mfillinois | 5:b77b678ed22f | 4 | #include "m3pi.h" |
dmcohen24 | 0:1802ead3667e | 5 | |
dmcohen24 | 3:0359b918f658 | 6 | //DigitalOut enable(p30); |
dmcohen24 | 3:0359b918f658 | 7 | |
mfillinois | 5:b77b678ed22f | 8 | //Ticker timer; |
dmcohen24 | 3:0359b918f658 | 9 | |
dmcohen24 | 3:0359b918f658 | 10 | I2C* i2c = new I2C(p28, p27); |
mfillinois | 5:b77b678ed22f | 11 | Serial bt(p13, p14); |
mfillinois | 5:b77b678ed22f | 12 | m3pi pi; |
dmcohen24 | 0:1802ead3667e | 13 | |
mfillinois | 5:b77b678ed22f | 14 | DigitalOut led1(LED1); DigitalOut led2(LED2); |
mfillinois | 5:b77b678ed22f | 15 | DigitalOut led3(LED3); DigitalOut led4(LED4); |
dmcohen24 | 0:1802ead3667e | 16 | |
mfillinois | 5:b77b678ed22f | 17 | InterruptIn event(p26); |
dmcohen24 | 3:0359b918f658 | 18 | |
dmcohen24 | 3:0359b918f658 | 19 | SI1143 sensor1(i2c, p30, p29, 0x01); |
mfillinois | 5:b77b678ed22f | 20 | //SI1143 sensor2(i2c, p25, p26, 0x02); // p25, p26 |
dmcohen24 | 3:0359b918f658 | 21 | |
dmcohen24 | 3:0359b918f658 | 22 | //InterruptIn prox_meas(p26); //26 |
dmcohen24 | 3:0359b918f658 | 23 | int sense1a, sense1b, sense2a, sense2b; |
dmcohen24 | 2:8798491332ed | 24 | |
mfillinois | 5:b77b678ed22f | 25 | //int total = 1000; |
mfillinois | 5:b77b678ed22f | 26 | int countingstuffpoop = 0; |
mfillinois | 5:b77b678ed22f | 27 | |
mfillinois | 5:b77b678ed22f | 28 | void meas_int() |
mfillinois | 5:b77b678ed22f | 29 | { |
dmcohen24 | 2:8798491332ed | 30 | led1 = 1; |
mfillinois | 5:b77b678ed22f | 31 | sense1a = sensor1.read_ps1(); |
mfillinois | 5:b77b678ed22f | 32 | sense1b = sensor1.read_ps2(); |
mfillinois | 5:b77b678ed22f | 33 | //sense2a = sensor2.get_ps1(1); |
mfillinois | 5:b77b678ed22f | 34 | //sense2b = sensor2.get_ps2(1); |
mfillinois | 5:b77b678ed22f | 35 | //bt.printf("%d, %d;\r\n",sense1a, sense1b); |
mfillinois | 5:b77b678ed22f | 36 | //wait(0.001); |
mfillinois | 5:b77b678ed22f | 37 | |
mfillinois | 5:b77b678ed22f | 38 | countingstuffpoop++; |
mfillinois | 5:b77b678ed22f | 39 | if(countingstuffpoop > 1000) |
mfillinois | 5:b77b678ed22f | 40 | { |
mfillinois | 5:b77b678ed22f | 41 | led4 = 0; |
mfillinois | 5:b77b678ed22f | 42 | } |
mfillinois | 5:b77b678ed22f | 43 | |
mfillinois | 5:b77b678ed22f | 44 | sensor1.clear_int(); |
dmcohen24 | 3:0359b918f658 | 45 | led1 = 0; |
dmcohen24 | 2:8798491332ed | 46 | } |
dmcohen24 | 2:8798491332ed | 47 | |
dmcohen24 | 0:1802ead3667e | 48 | int main() |
dmcohen24 | 2:8798491332ed | 49 | { |
dmcohen24 | 0:1802ead3667e | 50 | // Setup the baseline |
dmcohen24 | 3:0359b918f658 | 51 | //sensor1.restart(i2c, 0x01); |
dmcohen24 | 3:0359b918f658 | 52 | //printf("%d ",sensor1.adrs); |
dmcohen24 | 3:0359b918f658 | 53 | //sensor2.restart(i2c, 0x02); |
dmcohen24 | 3:0359b918f658 | 54 | //printf("%d\r\n",sensor2.adrs); |
dmcohen24 | 3:0359b918f658 | 55 | led2 = 0; |
dmcohen24 | 3:0359b918f658 | 56 | wait(1); |
mfillinois | 5:b77b678ed22f | 57 | |
mfillinois | 5:b77b678ed22f | 58 | event.fall(&meas_int); |
mfillinois | 5:b77b678ed22f | 59 | //timer.attach(&meas_int, 0.01); |
mfillinois | 5:b77b678ed22f | 60 | sensor1.start_ps_auto(); |
mfillinois | 5:b77b678ed22f | 61 | led4 = 1; |
mfillinois | 5:b77b678ed22f | 62 | //pi.left(0.1); |
dmcohen24 | 3:0359b918f658 | 63 | |
dmcohen24 | 0:1802ead3667e | 64 | while(1) |
dmcohen24 | 0:1802ead3667e | 65 | { |
dmcohen24 | 0:1802ead3667e | 66 | // Read each led sensor |
dmcohen24 | 2:8798491332ed | 67 | //sense1 = sensor.get_ps1(1); |
dmcohen24 | 2:8798491332ed | 68 | |
dmcohen24 | 0:1802ead3667e | 69 | //Numeriacl output through terminal |
dmcohen24 | 2:8798491332ed | 70 | led1 = 0; |
dmcohen24 | 3:0359b918f658 | 71 | led2 = 0; |
dmcohen24 | 0:1802ead3667e | 72 | } |
dmcohen24 | 3:0359b918f658 | 73 | } |