A LineFollower library for ASEE-2014
LineFollower.cpp@0:2623af9e8ef3, 2014-02-18 (annotated)
- Committer:
- blu12758
- Date:
- Tue Feb 18 04:14:48 2014 +0000
- Revision:
- 0:2623af9e8ef3
- Child:
- 1:c319e24af8df
First commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
blu12758 | 0:2623af9e8ef3 | 1 | #include "LineFollower.h" |
blu12758 | 0:2623af9e8ef3 | 2 | #include "mbed.h" |
blu12758 | 0:2623af9e8ef3 | 3 | #include <stdint.h> |
blu12758 | 0:2623af9e8ef3 | 4 | |
blu12758 | 0:2623af9e8ef3 | 5 | /** Create a Line Follower interface for an IR Sensor Array |
blu12758 | 0:2623af9e8ef3 | 6 | * |
blu12758 | 0:2623af9e8ef3 | 7 | * @param ir1 IR Sensor 1 |
blu12758 | 0:2623af9e8ef3 | 8 | * @param ir2 IR Sensor 2 |
blu12758 | 0:2623af9e8ef3 | 9 | * @param ir3 IR Sensor 3 |
blu12758 | 0:2623af9e8ef3 | 10 | * @param ir4 IR Sensor 4 |
blu12758 | 0:2623af9e8ef3 | 11 | * @param ir5 IR Sensor 5 |
blu12758 | 0:2623af9e8ef3 | 12 | * @param ir6 IR Sensor 6 |
blu12758 | 0:2623af9e8ef3 | 13 | * @param ir7 IR Sensor 7 |
blu12758 | 0:2623af9e8ef3 | 14 | * @param ir8 IR Sensor 8 |
blu12758 | 0:2623af9e8ef3 | 15 | */ |
blu12758 | 0:2623af9e8ef3 | 16 | LineFollower::Linefollower(DigitalIn ir1, DigitalIn ir2, DigitalIn ir3, DigitalIn ir4, |
blu12758 | 0:2623af9e8ef3 | 17 | DigitalIn ir5, DigitalIn ir6, DigitalIn ir7, DigitalIn ir8): |
blu12758 | 0:2623af9e8ef3 | 18 | _ir1(ir1), _ir2(ir2), _ir3(ir3), _ir4(ir4), _ir5(ir5), _ir6(ir6), |
blu12758 | 0:2623af9e8ef3 | 19 | _ir7(ir7), _ir8(ir8){ |
blu12758 | 0:2623af9e8ef3 | 20 | |
blu12758 | 0:2623af9e8ef3 | 21 | } |
blu12758 | 0:2623af9e8ef3 | 22 | |
blu12758 | 0:2623af9e8ef3 | 23 | |
blu12758 | 0:2623af9e8ef3 | 24 | /** Read the value of a LineFollower object |
blu12758 | 0:2623af9e8ef3 | 25 | * |
blu12758 | 0:2623af9e8ef3 | 26 | * @return The value of the Sensor |
blu12758 | 0:2623af9e8ef3 | 27 | */ |
blu12758 | 0:2623af9e8ef3 | 28 | uint8_t LineFollower::read(){ |
blu12758 | 0:2623af9e8ef3 | 29 | uint8_t binary = 0; |
blu12758 | 0:2623af9e8ef3 | 30 | |
blu12758 | 0:2623af9e8ef3 | 31 | array[0] = _ir1; |
blu12758 | 0:2623af9e8ef3 | 32 | array[1] = _ir2; |
blu12758 | 0:2623af9e8ef3 | 33 | array[2] = _ir3; |
blu12758 | 0:2623af9e8ef3 | 34 | array[3] = _ir4; |
blu12758 | 0:2623af9e8ef3 | 35 | array[4] = _ir5; |
blu12758 | 0:2623af9e8ef3 | 36 | array[5] = _ir6; |
blu12758 | 0:2623af9e8ef3 | 37 | array[6] = _ir7; |
blu12758 | 0:2623af9e8ef3 | 38 | array[7] = _ir8; |
blu12758 | 0:2623af9e8ef3 | 39 | |
blu12758 | 0:2623af9e8ef3 | 40 | for(int i=0; i<=8; i++){ |
blu12758 | 0:2623af9e8ef3 | 41 | binary += array[i] |
blu12758 | 0:2623af9e8ef3 | 42 | } |
blu12758 | 0:2623af9e8ef3 | 43 | |
blu12758 | 0:2623af9e8ef3 | 44 | } |