Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ELEC351 by
COLOURS.cpp@57:aba1296e51b1, 2018-08-15 (annotated)
- Committer:
- thomasmorris
- Date:
- Wed Aug 15 21:34:59 2018 +0000
- Revision:
- 57:aba1296e51b1
- Parent:
- 56:bc5345bc6650
Final Version
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
thomasmorris | 56:bc5345bc6650 | 1 | #include "COLOURS.hpp" |
thomasmorris | 56:bc5345bc6650 | 2 | |
thomasmorris | 56:bc5345bc6650 | 3 | |
thomasmorris | 56:bc5345bc6650 | 4 | int temp_colour_data_1 = 0; |
thomasmorris | 56:bc5345bc6650 | 5 | int temp_colour_data_2 = 0; |
thomasmorris | 56:bc5345bc6650 | 6 | int temp_colour_data_3 = 0; |
thomasmorris | 56:bc5345bc6650 | 7 | int temp_colour_data_4 = 0; |
thomasmorris | 56:bc5345bc6650 | 8 | int temp_colour_data_5 = 0; |
thomasmorris | 56:bc5345bc6650 | 9 | int temp_colour_data_6 = 0; |
thomasmorris | 56:bc5345bc6650 | 10 | int temp_colour_data_7 = 0; |
thomasmorris | 56:bc5345bc6650 | 11 | int temp_colour_data_8 = 0; |
thomasmorris | 56:bc5345bc6650 | 12 | int temp_colour_data_9 = 0; |
thomasmorris | 56:bc5345bc6650 | 13 | |
thomasmorris | 56:bc5345bc6650 | 14 | int Cubelet_Colours[9] = {0,0,0,0,0,0,0,0,0};//9 cubelets store colours here |
thomasmorris | 56:bc5345bc6650 | 15 | |
thomasmorris | 56:bc5345bc6650 | 16 | |
thomasmorris | 56:bc5345bc6650 | 17 | Colours convert (int Colour) |
thomasmorris | 56:bc5345bc6650 | 18 | { |
thomasmorris | 56:bc5345bc6650 | 19 | Colours colours_return_value; |
thomasmorris | 56:bc5345bc6650 | 20 | if(Colour == 1) |
thomasmorris | 56:bc5345bc6650 | 21 | { |
thomasmorris | 56:bc5345bc6650 | 22 | colours_return_value = White; |
thomasmorris | 56:bc5345bc6650 | 23 | } |
thomasmorris | 56:bc5345bc6650 | 24 | else if(Colour == 2) |
thomasmorris | 56:bc5345bc6650 | 25 | { |
thomasmorris | 56:bc5345bc6650 | 26 | colours_return_value = Orange; |
thomasmorris | 56:bc5345bc6650 | 27 | } |
thomasmorris | 56:bc5345bc6650 | 28 | else if(Colour == 3) |
thomasmorris | 56:bc5345bc6650 | 29 | { |
thomasmorris | 56:bc5345bc6650 | 30 | colours_return_value = Blue; |
thomasmorris | 56:bc5345bc6650 | 31 | } |
thomasmorris | 56:bc5345bc6650 | 32 | else if(Colour == 4) |
thomasmorris | 56:bc5345bc6650 | 33 | { |
thomasmorris | 56:bc5345bc6650 | 34 | colours_return_value = Red; |
thomasmorris | 56:bc5345bc6650 | 35 | } |
thomasmorris | 56:bc5345bc6650 | 36 | else if(Colour == 5) |
thomasmorris | 56:bc5345bc6650 | 37 | { |
thomasmorris | 56:bc5345bc6650 | 38 | colours_return_value = Green; |
thomasmorris | 56:bc5345bc6650 | 39 | } |
thomasmorris | 56:bc5345bc6650 | 40 | else if(Colour == 6) |
thomasmorris | 56:bc5345bc6650 | 41 | { |
thomasmorris | 56:bc5345bc6650 | 42 | colours_return_value = Yellow; |
thomasmorris | 56:bc5345bc6650 | 43 | } |
thomasmorris | 56:bc5345bc6650 | 44 | return colours_return_value; |
thomasmorris | 56:bc5345bc6650 | 45 | } |
thomasmorris | 57:aba1296e51b1 | 46 | |
thomasmorris | 57:aba1296e51b1 | 47 | char Value_convert (Colours value) |
thomasmorris | 57:aba1296e51b1 | 48 | { |
thomasmorris | 57:aba1296e51b1 | 49 | char Return_value; |
thomasmorris | 57:aba1296e51b1 | 50 | if(value == White){Return_value = 'W';} |
thomasmorris | 57:aba1296e51b1 | 51 | else if(value == Orange){Return_value = 'O';} |
thomasmorris | 57:aba1296e51b1 | 52 | else if(value == Blue){Return_value = 'B';} |
thomasmorris | 57:aba1296e51b1 | 53 | else if(value == Red){Return_value = 'R';} |
thomasmorris | 57:aba1296e51b1 | 54 | else if(value == Green){Return_value = 'G';} |
thomasmorris | 57:aba1296e51b1 | 55 | else if(value == Yellow){Return_value = 'Y';} |
thomasmorris | 57:aba1296e51b1 | 56 | |
thomasmorris | 57:aba1296e51b1 | 57 | return Return_value; |
thomasmorris | 57:aba1296e51b1 | 58 | } |
thomasmorris | 56:bc5345bc6650 | 59 | void Store_Cubelet_data() |
thomasmorris | 56:bc5345bc6650 | 60 | { |
thomasmorris | 56:bc5345bc6650 | 61 | if((8 >= colour_data) && (colour_data <= 15)) |
thomasmorris | 56:bc5345bc6650 | 62 | { |
thomasmorris | 56:bc5345bc6650 | 63 | temp_colour_data_1 = colour_data - 8;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 64 | Cubelet_Colours[0] = temp_colour_data_1;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 65 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 66 | } |
thomasmorris | 56:bc5345bc6650 | 67 | |
thomasmorris | 56:bc5345bc6650 | 68 | if((16 >= colour_data) && (colour_data <= 23)) |
thomasmorris | 56:bc5345bc6650 | 69 | { |
thomasmorris | 56:bc5345bc6650 | 70 | temp_colour_data_2 = colour_data - 16;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 71 | Cubelet_Colours[1] = temp_colour_data_2;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 72 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 73 | } |
thomasmorris | 56:bc5345bc6650 | 74 | if((24 >= colour_data) && (colour_data <= 31)) |
thomasmorris | 56:bc5345bc6650 | 75 | { |
thomasmorris | 56:bc5345bc6650 | 76 | temp_colour_data_3 = colour_data - 24;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 77 | Cubelet_Colours[2] = temp_colour_data_3;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 78 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 79 | } |
thomasmorris | 56:bc5345bc6650 | 80 | if((32 >= colour_data) && (colour_data <= 39)) |
thomasmorris | 56:bc5345bc6650 | 81 | { |
thomasmorris | 56:bc5345bc6650 | 82 | temp_colour_data_4 = colour_data - 32;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 83 | Cubelet_Colours[3] = temp_colour_data_4;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 84 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 85 | } |
thomasmorris | 56:bc5345bc6650 | 86 | if((40 >= colour_data) && (colour_data <= 47)) |
thomasmorris | 56:bc5345bc6650 | 87 | { |
thomasmorris | 56:bc5345bc6650 | 88 | temp_colour_data_5 = colour_data - 40;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 89 | Cubelet_Colours[4] = temp_colour_data_5;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 90 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 91 | } |
thomasmorris | 56:bc5345bc6650 | 92 | if((48 >= colour_data) && (colour_data <= 55)) |
thomasmorris | 56:bc5345bc6650 | 93 | { |
thomasmorris | 56:bc5345bc6650 | 94 | temp_colour_data_6 = colour_data - 48;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 95 | Cubelet_Colours[5] = temp_colour_data_6;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 96 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 97 | } |
thomasmorris | 56:bc5345bc6650 | 98 | if((56 >= colour_data) && (colour_data <= 63)) |
thomasmorris | 56:bc5345bc6650 | 99 | { |
thomasmorris | 56:bc5345bc6650 | 100 | temp_colour_data_7 = colour_data - 56;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 101 | Cubelet_Colours[6] = temp_colour_data_7;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 102 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 103 | } |
thomasmorris | 56:bc5345bc6650 | 104 | if((64 >= colour_data) && (colour_data <= 71)) |
thomasmorris | 56:bc5345bc6650 | 105 | { |
thomasmorris | 56:bc5345bc6650 | 106 | temp_colour_data_8 = colour_data - 64;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 107 | Cubelet_Colours[7] = temp_colour_data_8;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 108 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 109 | } |
thomasmorris | 56:bc5345bc6650 | 110 | if((72 >= colour_data) && (colour_data <= 79)) |
thomasmorris | 56:bc5345bc6650 | 111 | { |
thomasmorris | 56:bc5345bc6650 | 112 | temp_colour_data_9 = colour_data - 72;//Result shall be the colour |
thomasmorris | 56:bc5345bc6650 | 113 | Cubelet_Colours[8] = temp_colour_data_9;//Stores the colour value to the mememory map |
thomasmorris | 56:bc5345bc6650 | 114 | //take colour_data postion value and subtract it and you will be left with just the colour |
thomasmorris | 56:bc5345bc6650 | 115 | } |
thomasmorris | 56:bc5345bc6650 | 116 | |
thomasmorris | 56:bc5345bc6650 | 117 | |
thomasmorris | 56:bc5345bc6650 | 118 | if(Cubelet_Colours[5] == 1)//Store data to the white side |
thomasmorris | 56:bc5345bc6650 | 119 | { |
thomasmorris | 56:bc5345bc6650 | 120 | CubeMap[0][0][0] = convert(Cubelet_Colours[0]); |
thomasmorris | 56:bc5345bc6650 | 121 | CubeMap[0][0][1] = convert(Cubelet_Colours[1]); |
thomasmorris | 56:bc5345bc6650 | 122 | CubeMap[0][0][2] = convert(Cubelet_Colours[2]); |
thomasmorris | 56:bc5345bc6650 | 123 | CubeMap[0][1][0] = convert(Cubelet_Colours[3]); |
thomasmorris | 56:bc5345bc6650 | 124 | CubeMap[0][1][1] = convert(Cubelet_Colours[4]); |
thomasmorris | 56:bc5345bc6650 | 125 | CubeMap[0][1][2] = convert(Cubelet_Colours[5]); |
thomasmorris | 56:bc5345bc6650 | 126 | CubeMap[0][2][0] = convert(Cubelet_Colours[6]); |
thomasmorris | 56:bc5345bc6650 | 127 | CubeMap[0][2][1] = convert(Cubelet_Colours[7]); |
thomasmorris | 56:bc5345bc6650 | 128 | CubeMap[0][2][2] = convert(Cubelet_Colours[8]); |
thomasmorris | 56:bc5345bc6650 | 129 | //Store this to the white face |
thomasmorris | 56:bc5345bc6650 | 130 | } |
thomasmorris | 56:bc5345bc6650 | 131 | if(Cubelet_Colours[5] == 2)//Store data to the orange side |
thomasmorris | 56:bc5345bc6650 | 132 | { |
thomasmorris | 56:bc5345bc6650 | 133 | CubeMap[1][0][0] = convert(Cubelet_Colours[0]); |
thomasmorris | 56:bc5345bc6650 | 134 | CubeMap[1][0][1] = convert(Cubelet_Colours[1]); |
thomasmorris | 56:bc5345bc6650 | 135 | CubeMap[1][0][2] = convert(Cubelet_Colours[2]); |
thomasmorris | 56:bc5345bc6650 | 136 | CubeMap[1][1][0] = convert(Cubelet_Colours[3]); |
thomasmorris | 56:bc5345bc6650 | 137 | CubeMap[1][1][1] = convert(Cubelet_Colours[4]); |
thomasmorris | 56:bc5345bc6650 | 138 | CubeMap[1][1][2] = convert(Cubelet_Colours[5]); |
thomasmorris | 56:bc5345bc6650 | 139 | CubeMap[1][2][0] = convert(Cubelet_Colours[6]); |
thomasmorris | 56:bc5345bc6650 | 140 | CubeMap[1][2][1] = convert(Cubelet_Colours[7]); |
thomasmorris | 56:bc5345bc6650 | 141 | CubeMap[1][2][2] = convert(Cubelet_Colours[8]); |
thomasmorris | 56:bc5345bc6650 | 142 | //Store this to the white face |
thomasmorris | 56:bc5345bc6650 | 143 | } |
thomasmorris | 56:bc5345bc6650 | 144 | if(Cubelet_Colours[5] == 3)//Store data to the blue side |
thomasmorris | 56:bc5345bc6650 | 145 | { |
thomasmorris | 56:bc5345bc6650 | 146 | CubeMap[2][0][0] = convert(Cubelet_Colours[0]); |
thomasmorris | 56:bc5345bc6650 | 147 | CubeMap[2][0][1] = convert(Cubelet_Colours[1]); |
thomasmorris | 56:bc5345bc6650 | 148 | CubeMap[2][0][2] = convert(Cubelet_Colours[2]); |
thomasmorris | 56:bc5345bc6650 | 149 | CubeMap[2][1][0] = convert(Cubelet_Colours[3]); |
thomasmorris | 56:bc5345bc6650 | 150 | CubeMap[2][1][1] = convert(Cubelet_Colours[4]); |
thomasmorris | 56:bc5345bc6650 | 151 | CubeMap[2][1][2] = convert(Cubelet_Colours[5]); |
thomasmorris | 56:bc5345bc6650 | 152 | CubeMap[2][2][0] = convert(Cubelet_Colours[6]); |
thomasmorris | 56:bc5345bc6650 | 153 | CubeMap[2][2][1] = convert(Cubelet_Colours[7]); |
thomasmorris | 56:bc5345bc6650 | 154 | CubeMap[2][2][2] = convert(Cubelet_Colours[8]); |
thomasmorris | 56:bc5345bc6650 | 155 | //Store this to the white face |
thomasmorris | 56:bc5345bc6650 | 156 | } |
thomasmorris | 56:bc5345bc6650 | 157 | if(Cubelet_Colours[5] == 4)//Store data to the red side |
thomasmorris | 56:bc5345bc6650 | 158 | { |
thomasmorris | 56:bc5345bc6650 | 159 | CubeMap[3][0][0] = convert(Cubelet_Colours[0]); |
thomasmorris | 56:bc5345bc6650 | 160 | CubeMap[3][0][1] = convert(Cubelet_Colours[1]); |
thomasmorris | 56:bc5345bc6650 | 161 | CubeMap[3][0][2] = convert(Cubelet_Colours[2]); |
thomasmorris | 56:bc5345bc6650 | 162 | CubeMap[3][1][0] = convert(Cubelet_Colours[3]); |
thomasmorris | 56:bc5345bc6650 | 163 | CubeMap[3][1][1] = convert(Cubelet_Colours[4]); |
thomasmorris | 56:bc5345bc6650 | 164 | CubeMap[3][1][2] = convert(Cubelet_Colours[5]); |
thomasmorris | 56:bc5345bc6650 | 165 | CubeMap[3][2][0] = convert(Cubelet_Colours[6]); |
thomasmorris | 56:bc5345bc6650 | 166 | CubeMap[3][2][1] = convert(Cubelet_Colours[7]); |
thomasmorris | 56:bc5345bc6650 | 167 | CubeMap[3][2][2] = convert(Cubelet_Colours[8]); |
thomasmorris | 56:bc5345bc6650 | 168 | //Store this to the white face |
thomasmorris | 56:bc5345bc6650 | 169 | } |
thomasmorris | 56:bc5345bc6650 | 170 | if(Cubelet_Colours[5] == 5)//Store data to the green side |
thomasmorris | 56:bc5345bc6650 | 171 | { |
thomasmorris | 56:bc5345bc6650 | 172 | CubeMap[4][0][0] = convert(Cubelet_Colours[0]); |
thomasmorris | 56:bc5345bc6650 | 173 | CubeMap[4][0][1] = convert(Cubelet_Colours[1]); |
thomasmorris | 56:bc5345bc6650 | 174 | CubeMap[4][0][2] = convert(Cubelet_Colours[2]); |
thomasmorris | 56:bc5345bc6650 | 175 | CubeMap[4][1][0] = convert(Cubelet_Colours[3]); |
thomasmorris | 56:bc5345bc6650 | 176 | CubeMap[4][1][1] = convert(Cubelet_Colours[4]); |
thomasmorris | 56:bc5345bc6650 | 177 | CubeMap[4][1][2] = convert(Cubelet_Colours[5]); |
thomasmorris | 56:bc5345bc6650 | 178 | CubeMap[4][2][0] = convert(Cubelet_Colours[6]); |
thomasmorris | 56:bc5345bc6650 | 179 | CubeMap[4][2][1] = convert(Cubelet_Colours[7]); |
thomasmorris | 56:bc5345bc6650 | 180 | CubeMap[4][2][2] = convert(Cubelet_Colours[8]); |
thomasmorris | 56:bc5345bc6650 | 181 | //Store this to the white face |
thomasmorris | 56:bc5345bc6650 | 182 | } |
thomasmorris | 56:bc5345bc6650 | 183 | if(Cubelet_Colours[5] == 6)//Store data to the yellow side |
thomasmorris | 56:bc5345bc6650 | 184 | { |
thomasmorris | 56:bc5345bc6650 | 185 | CubeMap[5][0][0] = convert(Cubelet_Colours[0]); |
thomasmorris | 56:bc5345bc6650 | 186 | CubeMap[5][0][1] = convert(Cubelet_Colours[1]); |
thomasmorris | 56:bc5345bc6650 | 187 | CubeMap[5][0][2] = convert(Cubelet_Colours[2]); |
thomasmorris | 56:bc5345bc6650 | 188 | CubeMap[5][1][0] = convert(Cubelet_Colours[3]); |
thomasmorris | 56:bc5345bc6650 | 189 | CubeMap[5][1][1] = convert(Cubelet_Colours[4]); |
thomasmorris | 56:bc5345bc6650 | 190 | CubeMap[5][1][2] = convert(Cubelet_Colours[5]); |
thomasmorris | 56:bc5345bc6650 | 191 | CubeMap[5][2][0] = convert(Cubelet_Colours[6]); |
thomasmorris | 56:bc5345bc6650 | 192 | CubeMap[5][2][1] = convert(Cubelet_Colours[7]); |
thomasmorris | 56:bc5345bc6650 | 193 | CubeMap[5][2][2] = convert(Cubelet_Colours[8]); |
thomasmorris | 56:bc5345bc6650 | 194 | //Store this to the white face |
thomasmorris | 56:bc5345bc6650 | 195 | } |
thomasmorris | 56:bc5345bc6650 | 196 | } |