Mini projet LOO
Dependencies: mbed APDS_9960 mbed-rtos
Home du projet
src/cLigne.cpp@40:08490d120ec4, 2016-04-24 (annotated)
- Committer:
- Willheisen
- Date:
- Sun Apr 24 22:11:55 2016 +0000
- Revision:
- 40:08490d120ec4
- Parent:
- 18:45dbd9948c97
- Child:
- 29:95469b25e187
VERSION FINALE
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Willheisen | 3:493dd1cf30a4 | 1 | // Définition de la classe Ligne |
Willheisen | 3:493dd1cf30a4 | 2 | |
Willheisen | 3:493dd1cf30a4 | 3 | #include "cLigne.h" |
Willheisen | 3:493dd1cf30a4 | 4 | |
clementdoreau | 7:4b283e36b147 | 5 | cLigne::cLigne() { |
clementdoreau | 7:4b283e36b147 | 6 | // variables à 0 |
clementdoreau | 7:4b283e36b147 | 7 | _positionX = 0; |
clementdoreau | 7:4b283e36b147 | 8 | _positionY = 0; |
clementdoreau | 7:4b283e36b147 | 9 | _orientation = 1; |
clementdoreau | 7:4b283e36b147 | 10 | // Positionnement des leds |
clementdoreau | 7:4b283e36b147 | 11 | // |0|1|2|3| |
Willheisen | 12:7afdbc7465ac | 12 | _Leds[0].setPositionX(_positionX - 1); |
clementdoreau | 7:4b283e36b147 | 13 | _Leds[0].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 14 | _Leds[1].setPositionX(_positionX); |
clementdoreau | 7:4b283e36b147 | 15 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 16 | _Leds[2].setPositionX(_positionX + 1); |
clementdoreau | 7:4b283e36b147 | 17 | _Leds[2].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 18 | _Leds[3].setPositionX(_positionX + 2); |
clementdoreau | 7:4b283e36b147 | 19 | _Leds[3].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 20 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 21 | _Leds[i].setOldPositionX(_Leds[i].getPositionX()); |
Willheisen | 12:7afdbc7465ac | 22 | } |
Willheisen | 12:7afdbc7465ac | 23 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 24 | _Leds[i].setOldPositionY(_Leds[i].getPositionY()); |
Willheisen | 12:7afdbc7465ac | 25 | } |
Willheisen | 12:7afdbc7465ac | 26 | _typeForme = 0; |
Willheisen | 3:493dd1cf30a4 | 27 | } |
Willheisen | 3:493dd1cf30a4 | 28 | |
clementdoreau | 7:4b283e36b147 | 29 | cLigne::cLigne(unsigned char x, unsigned char y) { |
clementdoreau | 7:4b283e36b147 | 30 | // variables à 0 |
clementdoreau | 7:4b283e36b147 | 31 | _positionX = x; |
clementdoreau | 7:4b283e36b147 | 32 | _positionY = y; |
clementdoreau | 7:4b283e36b147 | 33 | _orientation = 1; |
clementdoreau | 7:4b283e36b147 | 34 | // Positionnement des leds |
clementdoreau | 7:4b283e36b147 | 35 | // |0|1|2|3| |
clementdoreau | 18:45dbd9948c97 | 36 | _Leds[0].setPositionX(_positionX); |
clementdoreau | 7:4b283e36b147 | 37 | _Leds[0].setPositionY(_positionY); |
clementdoreau | 18:45dbd9948c97 | 38 | _Leds[1].setPositionX(_positionX + 1); |
clementdoreau | 7:4b283e36b147 | 39 | _Leds[1].setPositionY(_positionY); |
clementdoreau | 18:45dbd9948c97 | 40 | _Leds[2].setPositionX(_positionX + 2); |
clementdoreau | 7:4b283e36b147 | 41 | _Leds[2].setPositionY(_positionY); |
clementdoreau | 18:45dbd9948c97 | 42 | _Leds[3].setPositionX(_positionX + 3); |
clementdoreau | 7:4b283e36b147 | 43 | _Leds[3].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 44 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 45 | _Leds[i].setOldPositionX(_Leds[i].getPositionX()); |
Willheisen | 12:7afdbc7465ac | 46 | } |
Willheisen | 12:7afdbc7465ac | 47 | for(unsigned char i = 0; i<4; i++) { |
Willheisen | 12:7afdbc7465ac | 48 | _Leds[i].setOldPositionY(_Leds[i].getPositionY()); |
Willheisen | 12:7afdbc7465ac | 49 | } |
Willheisen | 12:7afdbc7465ac | 50 | _typeForme = 0; |
Willheisen | 3:493dd1cf30a4 | 51 | } |
Willheisen | 3:493dd1cf30a4 | 52 | |
clementdoreau | 7:4b283e36b147 | 53 | |
clementdoreau | 7:4b283e36b147 | 54 | void cLigne::rotationHoraire() { |
Willheisen | 12:7afdbc7465ac | 55 | // Sauvegarde des anciennes positions |
Willheisen | 12:7afdbc7465ac | 56 | for (unsigned char i = 0; i < 4; i++) { |
Willheisen | 12:7afdbc7465ac | 57 | _Leds[i].setOldPositionX(_Leds[i].getPositionX()); |
Willheisen | 12:7afdbc7465ac | 58 | _Leds[i].setOldPositionY(_Leds[i].getPositionY()); |
Willheisen | 12:7afdbc7465ac | 59 | } |
Willheisen | 12:7afdbc7465ac | 60 | |
Willheisen | 12:7afdbc7465ac | 61 | switch (_orientation) { |
Willheisen | 12:7afdbc7465ac | 62 | case 1: |
Willheisen | 12:7afdbc7465ac | 63 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 64 | // |0| |
Willheisen | 12:7afdbc7465ac | 65 | // |1| |
Willheisen | 12:7afdbc7465ac | 66 | // |2| |
Willheisen | 12:7afdbc7465ac | 67 | // |3| |
Willheisen | 12:7afdbc7465ac | 68 | _Leds[0].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 69 | _Leds[0].setPositionY(_positionY - 1); |
Willheisen | 12:7afdbc7465ac | 70 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 71 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 72 | _Leds[2].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 73 | _Leds[2].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 74 | _Leds[3].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 75 | _Leds[3].setPositionY(_positionY + 2); |
Willheisen | 12:7afdbc7465ac | 76 | _orientation = 2; |
Willheisen | 12:7afdbc7465ac | 77 | break; |
Willheisen | 12:7afdbc7465ac | 78 | case 2: |
Willheisen | 12:7afdbc7465ac | 79 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 80 | // |3|2|1|0| |
Willheisen | 12:7afdbc7465ac | 81 | _Leds[0].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 82 | _Leds[0].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 83 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 84 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 85 | _Leds[2].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 86 | _Leds[2].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 87 | _Leds[3].setPositionX(_positionX - 2); |
Willheisen | 12:7afdbc7465ac | 88 | _Leds[3].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 89 | _orientation = 3; |
Willheisen | 12:7afdbc7465ac | 90 | break; |
Willheisen | 12:7afdbc7465ac | 91 | case 3: |
Willheisen | 12:7afdbc7465ac | 92 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 93 | // |3| |
Willheisen | 12:7afdbc7465ac | 94 | // |2| |
Willheisen | 12:7afdbc7465ac | 95 | // |1| |
Willheisen | 12:7afdbc7465ac | 96 | // |0| |
Willheisen | 12:7afdbc7465ac | 97 | _Leds[0].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 98 | _Leds[0].setPositionY(_positionY + 1); |
Willheisen | 12:7afdbc7465ac | 99 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 100 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 101 | _Leds[2].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 102 | _Leds[2].setPositionY(_positionY - 1); |
Willheisen | 12:7afdbc7465ac | 103 | _Leds[3].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 104 | _Leds[3].setPositionY(_positionY - 2); |
Willheisen | 12:7afdbc7465ac | 105 | _orientation = 4; |
Willheisen | 12:7afdbc7465ac | 106 | break; |
clementdoreau | 7:4b283e36b147 | 107 | |
Willheisen | 12:7afdbc7465ac | 108 | case 4: |
Willheisen | 12:7afdbc7465ac | 109 | // Positionnement des leds |
Willheisen | 12:7afdbc7465ac | 110 | // |0|1|2|3| |
Willheisen | 12:7afdbc7465ac | 111 | _Leds[0].setPositionX(_positionX - 1); |
Willheisen | 12:7afdbc7465ac | 112 | _Leds[0].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 113 | _Leds[1].setPositionX(_positionX); |
Willheisen | 12:7afdbc7465ac | 114 | _Leds[1].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 115 | _Leds[2].setPositionX(_positionX + 1); |
Willheisen | 12:7afdbc7465ac | 116 | _Leds[2].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 117 | _Leds[3].setPositionX(_positionX + 2); |
Willheisen | 12:7afdbc7465ac | 118 | _Leds[3].setPositionY(_positionY); |
Willheisen | 12:7afdbc7465ac | 119 | _orientation = 1; |
Willheisen | 12:7afdbc7465ac | 120 | break; |
Willheisen | 12:7afdbc7465ac | 121 | default: |
Willheisen | 12:7afdbc7465ac | 122 | break; |
Willheisen | 12:7afdbc7465ac | 123 | } |
clementdoreau | 7:4b283e36b147 | 124 | } |