Shape algorithm for location mapping.
Fork of Orientation_PerTile by
main.cpp@3:87945bd950e8, 2018-05-26 (annotated)
- Committer:
- el15tcd
- Date:
- Sat May 26 03:02:34 2018 +0000
- Revision:
- 3:87945bd950e8
- Parent:
- 2:8667325e74a9
Shape algorithm for location mapping.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el15tcd | 0:8a61e3541a5e | 1 | #include "mbed.h" |
el15tcd | 0:8a61e3541a5e | 2 | |
el15tcd | 0:8a61e3541a5e | 3 | BusOut myleds(LED4, LED3, LED2, LED1); |
el15tcd | 2:8667325e74a9 | 4 | |
el15tcd | 2:8667325e74a9 | 5 | int algorithm_update; |
el15tcd | 2:8667325e74a9 | 6 | |
el15tcd | 3:87945bd950e8 | 7 | int shape; //a value between 0 for off, and 5 for a square (with 6 for error) |
el15tcd | 3:87945bd950e8 | 8 | char tile1; |
el15tcd | 3:87945bd950e8 | 9 | char tile2; |
el15tcd | 3:87945bd950e8 | 10 | char tile3; |
el15tcd | 3:87945bd950e8 | 11 | char tile4; |
el15tcd | 3:87945bd950e8 | 12 | char tiles_combo; |
el15tcd | 0:8a61e3541a5e | 13 | |
el15tcd | 0:8a61e3541a5e | 14 | int main() |
el15tcd | 3:87945bd950e8 | 15 | { |
el15tcd | 2:8667325e74a9 | 16 | |
el15tcd | 2:8667325e74a9 | 17 | algorithm_update = 1; |
el15tcd | 1:c573caf40864 | 18 | |
el15tcd | 2:8667325e74a9 | 19 | while(algorithm_update == 1) { //set algorithm to 0 to end the algorithm |
el15tcd | 3:87945bd950e8 | 20 | |
el15tcd | 3:87945bd950e8 | 21 | check_tiles(); |
el15tcd | 3:87945bd950e8 | 22 | tiles_combo = tile1 + tile2 + tile3 + tile4; |
el15tcd | 3:87945bd950e8 | 23 | |
el15tcd | 3:87945bd950e8 | 24 | //check if all tiles are off |
el15tcd | 3:87945bd950e8 | 25 | if ((tile1 == 0x00) && (tile2 == 0x00) && (tile3 == 0x00) && (tile4 == 0x00)) { |
el15tcd | 3:87945bd950e8 | 26 | shape = 0; |
el15tcd | 3:87945bd950e8 | 27 | } else if ((tile1 == 0x07) && (tile2 == 0x07) && (tile3 == 0x07) && (tile4 == 0x07)) { //0x07 is 111 (on and sensor values) |
el15tcd | 3:87945bd950e8 | 28 | shape = 5; |
el15tcd | 3:87945bd950e8 | 29 | } else if (tiles_combo == 0x04) { //0x04 is 100 (on and no sensor values) |
el15tcd | 3:87945bd950e8 | 30 | shape = 1; |
el15tcd | 3:87945bd950e8 | 31 | } else if (tiles_combo == 0x0A) { //0x0A is 101 + 101 (on and 1 sensor active on each of two tiles) |
el15tcd | 3:87945bd950e8 | 32 | shape = 2; |
el15tcd | 3:87945bd950e8 | 33 | } else if (tiles_combo == 0x11) { //0x11 is 101 + 111 + 111 |
el15tcd | 3:87945bd950e8 | 34 | shape = 3; |
el15tcd | 3:87945bd950e8 | 35 | } else if (tiles_combo == 0x18) { //0x18 is 101 + 111 + 111 + 101 |
el15tcd | 3:87945bd950e8 | 36 | shape = 4; |
el15tcd | 3:87945bd950e8 | 37 | } else { |
el15tcd | 3:87945bd950e8 | 38 | shape = 6; |
el15tcd | 0:8a61e3541a5e | 39 | } |
el15tcd | 3:87945bd950e8 | 40 | |
el15tcd | 3:87945bd950e8 | 41 | if (shape != 6) { |
el15tcd | 3:87945bd950e8 | 42 | algorithm_update = 0; |
el15tcd | 3:87945bd950e8 | 43 | } |
el15tcd | 2:8667325e74a9 | 44 | |
el15tcd | 0:8a61e3541a5e | 45 | } |
el15tcd | 3:87945bd950e8 | 46 | //output shape value in desired format |
el15tcd | 3:87945bd950e8 | 47 | //ie return shape; |
el15tcd | 2:8667325e74a9 | 48 | } |
el15tcd | 2:8667325e74a9 | 49 | |
el15tcd | 3:87945bd950e8 | 50 | void check_tiles { |
el15tcd | 3:87945bd950e8 | 51 | //obtains the codeword for each tile |
el15tcd | 3:87945bd950e8 | 52 | //dependent upon the sensor code, but will update tiles 1 through 4 values |
el15tcd | 0:8a61e3541a5e | 53 | } |