example program that makes use of the LineSensors library to read a reflectance sensor array.
Dependencies: LineSensors
line_sensors_to_serial_24.cpp@0:20cf5a047c5e, 2014-10-15 (annotated)
- Committer:
- jmar11
- Date:
- Wed Oct 15 20:37:04 2014 +0000
- Revision:
- 0:20cf5a047c5e
First working commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jmar11 | 0:20cf5a047c5e | 1 | #include "mbed.h" |
jmar11 | 0:20cf5a047c5e | 2 | #include "LineSensors.h" |
jmar11 | 0:20cf5a047c5e | 3 | |
jmar11 | 0:20cf5a047c5e | 4 | Serial pc(USBTX, USBRX); |
jmar11 | 0:20cf5a047c5e | 5 | bool detect[8][3]; |
jmar11 | 0:20cf5a047c5e | 6 | LineSensors sensors(PTB8, PTB9, PTB10, PTB11, PTE2, PTE3, PTE4, PTE5, |
jmar11 | 0:20cf5a047c5e | 7 | PTC11, PTC10, PTC6, PTC5, PTC4, PTC3, PTC0, PTC7, |
jmar11 | 0:20cf5a047c5e | 8 | PTC9, PTC8, PTA5, PTA4, PTA12, PTD4, PTD5, PTA13); |
jmar11 | 0:20cf5a047c5e | 9 | |
jmar11 | 0:20cf5a047c5e | 10 | int main() { |
jmar11 | 0:20cf5a047c5e | 11 | pc.baud(115200); |
jmar11 | 0:20cf5a047c5e | 12 | pc.printf("\fPlease put all the sensors over white and press <enter>\n\r"); |
jmar11 | 0:20cf5a047c5e | 13 | pc.getc(); |
jmar11 | 0:20cf5a047c5e | 14 | |
jmar11 | 0:20cf5a047c5e | 15 | sensors.setThreshold(); |
jmar11 | 0:20cf5a047c5e | 16 | |
jmar11 | 0:20cf5a047c5e | 17 | pc.printf("here1\n\r"); |
jmar11 | 0:20cf5a047c5e | 18 | |
jmar11 | 0:20cf5a047c5e | 19 | pc.printf("The values of the line sensors will be shown shortly\n\r0 == white 1 == black\n\n\r"); |
jmar11 | 0:20cf5a047c5e | 20 | |
jmar11 | 0:20cf5a047c5e | 21 | wait(3); |
jmar11 | 0:20cf5a047c5e | 22 | |
jmar11 | 0:20cf5a047c5e | 23 | while(1){ |
jmar11 | 0:20cf5a047c5e | 24 | sensors.lineDetect(detect); |
jmar11 | 0:20cf5a047c5e | 25 | pc.printf("\f"); |
jmar11 | 0:20cf5a047c5e | 26 | for(int j = 0; j < 3; j++){ |
jmar11 | 0:20cf5a047c5e | 27 | for(int i = 0; i < 8; i++){ |
jmar11 | 0:20cf5a047c5e | 28 | if(detect[i][j]){ |
jmar11 | 0:20cf5a047c5e | 29 | pc.printf("1 "); |
jmar11 | 0:20cf5a047c5e | 30 | } |
jmar11 | 0:20cf5a047c5e | 31 | else{ |
jmar11 | 0:20cf5a047c5e | 32 | pc.printf("0 "); |
jmar11 | 0:20cf5a047c5e | 33 | } |
jmar11 | 0:20cf5a047c5e | 34 | } |
jmar11 | 0:20cf5a047c5e | 35 | } |
jmar11 | 0:20cf5a047c5e | 36 | } |
jmar11 | 0:20cf5a047c5e | 37 | } |