Library that can read an array of 8x3 reflectance sensors.
Dependencies: DigitalInOut2
Dependents: line_sensors_to_serial_24 R5
Fork of LineSensors by
Diff: LineSensors.cpp
- Revision:
- 1:a45634860f11
- Parent:
- 0:acd430185ac0
--- a/LineSensors.cpp Tue Oct 14 18:03:59 2014 +0000 +++ b/LineSensors.cpp Wed Oct 15 20:34:47 2014 +0000 @@ -12,14 +12,14 @@ sensors[0][2] = IO17;sensors[1][2] = IO18;sensors[2][2] = IO19;sensors[3][2] = IO20; sensors[4][2] = IO21;sensors[5][2] = IO22;sensors[6][2] = IO23;sensors[7][2] = IO24; - timeOut = 500000; + timeOut = 100000; } void LineSensors::setThreshold(){ read(); for(int j = 0; j < 3; j++){ for(int i = 0; i < 8; i++){ - thresh[i][j] = sensors[i][j]; + thresh[i][j] = sensVal[i][j]; thresh[i][j] *= 7; } } @@ -29,10 +29,8 @@ DigitalInOut2 sensor(sensors[0][0]); //attribute the first pin in the sensors array to sensor (the DigitalInOut2 object) for(int j = 0; j < 3; j++){ - for(int i = 0; i < 8; i++){ - sensor.gpio.mask = gpio_set(sensors[i][j]); //change the pin that is attributed to sensor (the DigitalInOut2 object) - sensor.output(); - sensor = 1; + for(int i = 0; i < 8; i ++){ + gpio_init_inout(&sensor.gpio, sensors[i][j], PIN_OUTPUT, PullNone, 1); //change the pin that is attributed to sensor (the DigitalInOut2 object) wait_us(15); sensor = 0; sensor.input(); @@ -47,12 +45,13 @@ } void LineSensors::lineDetect(bool out[8][3]){ + read(); for(int j = 0; j < 3; j++){ for(int i = 0; i < 8; i++){ - if(sensors[i][j] > thresh[i][j]) - out[i][j] = true; + if(sensVal[i][j] > thresh[i][j]) + out[i][j] = 1; else - out[i][j] = false; + out[i][j] = 0; } } } \ No newline at end of file