Proj 324 Final

Fork of ELEC351_Group_T by Plymouth ELEC351 Group T

Committer:
thomasmorris
Date:
Thu May 24 13:31:20 2018 +0000
Revision:
55:e0e684531825
Parent:
54:a4c5949707ca
Child:
56:bc5345bc6650
edge and corner colour list filling;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thomasmorris 53:71f59e195f06 1
thomasmorris 25:36699ed589ab 2 #include "SETUP.hpp"
thomasmorris 52:99915f5240b2 3
thomasmorris 54:a4c5949707ca 4 #define Cubelet_data_ready 1
thomasmorris 54:a4c5949707ca 5 #define Not_Cubelet_data_ready 0
thomasmorris 54:a4c5949707ca 6 /*
thomasmorris 54:a4c5949707ca 7 Colour lookup table
thomasmorris 54:a4c5949707ca 8 1 = White
thomasmorris 54:a4c5949707ca 9 2 = Red
thomasmorris 54:a4c5949707ca 10 3 = Orange
thomasmorris 54:a4c5949707ca 11 4 = Blue
thomasmorris 54:a4c5949707ca 12 5 = Green
thomasmorris 54:a4c5949707ca 13 6 = Yellow
thomasmorris 54:a4c5949707ca 14 */
thomasmorris 54:a4c5949707ca 15
thomasmorris 54:a4c5949707ca 16 //Colours Cubelet_Colours_string[];
thomasmorris 55:e0e684531825 17 int colour_data = 0;
thomasmorris 55:e0e684531825 18 int temp_colour_data_1 = 0;
thomasmorris 55:e0e684531825 19 int temp_colour_data_2 = 0;
thomasmorris 55:e0e684531825 20 int temp_colour_data_3 = 0;
thomasmorris 55:e0e684531825 21 int temp_colour_data_4 = 0;
thomasmorris 55:e0e684531825 22 int temp_colour_data_5 = 0;
thomasmorris 55:e0e684531825 23 int temp_colour_data_6 = 0;
thomasmorris 55:e0e684531825 24 int temp_colour_data_7 = 0;
thomasmorris 55:e0e684531825 25 int temp_colour_data_8 = 0;
thomasmorris 55:e0e684531825 26 int temp_colour_data_9 = 0;
thomasmorris 55:e0e684531825 27
thomasmorris 53:71f59e195f06 28 int SPI_RX_DATA = 0;
thomasmorris 53:71f59e195f06 29 int Cubelet_Colours[9] = {0,0,0,0,0,0,0,0,0};//9 cubelets store colours here
thomasmorris 53:71f59e195f06 30 int Received_data = 0;
thomasmorris 53:71f59e195f06 31 bool Data_from_slave[16] = {0};
thomasmorris 53:71f59e195f06 32
thomasmorris 52:99915f5240b2 33 //Interrupt service routine for handling the timeout of SW1
thomasmorris 52:99915f5240b2 34 void SW1TimeOutHandler() {
thomasmorris 52:99915f5240b2 35 SW1TimeOut.detach(); //Stop the timeout counter firing
thomasmorris 52:99915f5240b2 36 SW1.fall(&SW1FallingEdge); //Now wait for a falling edge
thomasmorris 52:99915f5240b2 37 }
thomasmorris 52:99915f5240b2 38 //Interrupt service routive for SW2 falling edge (release)
thomasmorris 52:99915f5240b2 39 void SW1FallingEdge() {
thomasmorris 52:99915f5240b2 40 SW1.fall(NULL); //Disable this interrupt
thomasmorris 52:99915f5240b2 41 SW1TimeOut.attach(&SW1TimeOutHandler, SW1_SW2_Timeout_Time); //Start timeout counter
thomasmorris 52:99915f5240b2 42 }
thomasmorris 52:99915f5240b2 43 //Interrupt service routine for handling the timeout of SW2
thomasmorris 52:99915f5240b2 44 void SW2TimeOutHandler() {
thomasmorris 52:99915f5240b2 45 SW2TimeOut.detach(); //Stop the timeout counter firing
thomasmorris 52:99915f5240b2 46 SW2.fall(&SW2FallingEdge); //Now wait for a falling edge
thomasmorris 52:99915f5240b2 47 }
thomasmorris 52:99915f5240b2 48 //Interrupt service routive for SW2 falling edge (release)
thomasmorris 52:99915f5240b2 49 void SW2FallingEdge() {
thomasmorris 52:99915f5240b2 50 SW2.fall(NULL); //Disable this interrupt
thomasmorris 52:99915f5240b2 51 SW2TimeOut.attach(&SW2TimeOutHandler, SW1_SW2_Timeout_Time); //Start timeout counter
thomasmorris 52:99915f5240b2 52 }
thomasmorris 47:6d128e500875 53 void LCD_Output()
thomasmorris 30:4cde05cc7c4f 54 {
thomasmorris 30:4cde05cc7c4f 55 while(1)
thomasmorris 29:64b1f95a807c 56 {
thomasmorris 53:71f59e195f06 57 //Write to the LCD
thomasmorris 7:dfe19413fdc2 58 }
thomasmorris 7:dfe19413fdc2 59 }
thomasmorris 47:6d128e500875 60 void Serial_Commands()
thomasmorris 22:eb4cc12087b2 61 {
thomasmorris 47:6d128e500875 62 while(1)
thomasmorris 47:6d128e500875 63 {
thomasmorris 52:99915f5240b2 64 Serial_Commands_Output(); //Enable Serial Commands
thomasmorris 47:6d128e500875 65 }
thomasmorris 22:eb4cc12087b2 66 }
thomasmorris 48:244d6d81bb52 67 void LED_Logging()
thomasmorris 48:244d6d81bb52 68 {
thomasmorris 48:244d6d81bb52 69 while(1)
thomasmorris 48:244d6d81bb52 70 {
thomasmorris 52:99915f5240b2 71 Log_Leds(); //Flashes the yellow led to indicate the logging mode
thomasmorris 48:244d6d81bb52 72 }
thomasmorris 48:244d6d81bb52 73 }
thomasmorris 53:71f59e195f06 74
thomasmorris 53:71f59e195f06 75 void SPI_INTERFACE()
thomasmorris 53:71f59e195f06 76 {
thomasmorris 53:71f59e195f06 77 //pc.printf("SPI Test \n");
thomasmorris 53:71f59e195f06 78 Thread::wait(1000);
thomasmorris 53:71f59e195f06 79 while(1)
thomasmorris 53:71f59e195f06 80 {
thomasmorris 53:71f59e195f06 81 cs= 0;
thomasmorris 54:a4c5949707ca 82 SPI_RX_DATA = spi.write(0xF0);
thomasmorris 53:71f59e195f06 83 wait_us(3);
thomasmorris 53:71f59e195f06 84 cs= 1;
thomasmorris 55:e0e684531825 85 colour_data = SPI_RX_DATA;
thomasmorris 53:71f59e195f06 86 pc.printf("Received data = %d\n", SPI_RX_DATA);
thomasmorris 55:e0e684531825 87 Thread::wait(1000);
thomasmorris 53:71f59e195f06 88 }
thomasmorris 53:71f59e195f06 89 }
thomasmorris 54:a4c5949707ca 90
thomasmorris 54:a4c5949707ca 91 Colours convert (int Colour)
thomasmorris 54:a4c5949707ca 92 {
thomasmorris 54:a4c5949707ca 93 Colours colours_return_value;
thomasmorris 54:a4c5949707ca 94 if(Colour == 1)
thomasmorris 54:a4c5949707ca 95 {
thomasmorris 54:a4c5949707ca 96 colours_return_value = White;
thomasmorris 54:a4c5949707ca 97 }
thomasmorris 54:a4c5949707ca 98 else if(Colour == 2)
thomasmorris 54:a4c5949707ca 99 {
thomasmorris 55:e0e684531825 100 colours_return_value = Orange;
thomasmorris 54:a4c5949707ca 101 }
thomasmorris 54:a4c5949707ca 102 else if(Colour == 3)
thomasmorris 54:a4c5949707ca 103 {
thomasmorris 55:e0e684531825 104 colours_return_value = Blue;
thomasmorris 54:a4c5949707ca 105 }
thomasmorris 54:a4c5949707ca 106 else if(Colour == 4)
thomasmorris 54:a4c5949707ca 107 {
thomasmorris 55:e0e684531825 108 colours_return_value = Red;
thomasmorris 54:a4c5949707ca 109 }
thomasmorris 54:a4c5949707ca 110 else if(Colour == 5)
thomasmorris 54:a4c5949707ca 111 {
thomasmorris 54:a4c5949707ca 112 colours_return_value = Green;
thomasmorris 54:a4c5949707ca 113 }
thomasmorris 54:a4c5949707ca 114 else if(Colour == 6)
thomasmorris 54:a4c5949707ca 115 {
thomasmorris 54:a4c5949707ca 116 colours_return_value = Yellow;
thomasmorris 54:a4c5949707ca 117 }
thomasmorris 54:a4c5949707ca 118 return colours_return_value;
thomasmorris 54:a4c5949707ca 119 }
thomasmorris 54:a4c5949707ca 120 void Store_Cubelet_data()
thomasmorris 55:e0e684531825 121 {
thomasmorris 55:e0e684531825 122 if((8 >= colour_data) && (colour_data <= 15))
thomasmorris 55:e0e684531825 123 {
thomasmorris 55:e0e684531825 124 temp_colour_data_1 = colour_data - 8;//Result shall be the colour
thomasmorris 55:e0e684531825 125 Cubelet_Colours[0] = temp_colour_data_1;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 126 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 127 }
thomasmorris 55:e0e684531825 128
thomasmorris 55:e0e684531825 129 if((16 >= colour_data) && (colour_data <= 23))
thomasmorris 55:e0e684531825 130 {
thomasmorris 55:e0e684531825 131 temp_colour_data_2 = colour_data - 16;//Result shall be the colour
thomasmorris 55:e0e684531825 132 Cubelet_Colours[1] = temp_colour_data_2;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 133 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 134 }
thomasmorris 55:e0e684531825 135 if((24 >= colour_data) && (colour_data <= 31))
thomasmorris 55:e0e684531825 136 {
thomasmorris 55:e0e684531825 137 temp_colour_data_3 = colour_data - 24;//Result shall be the colour
thomasmorris 55:e0e684531825 138 Cubelet_Colours[2] = temp_colour_data_3;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 139 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 140 }
thomasmorris 55:e0e684531825 141 if((32 >= colour_data) && (colour_data <= 39))
thomasmorris 55:e0e684531825 142 {
thomasmorris 55:e0e684531825 143 temp_colour_data_4 = colour_data - 32;//Result shall be the colour
thomasmorris 55:e0e684531825 144 Cubelet_Colours[3] = temp_colour_data_4;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 145 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 146 }
thomasmorris 55:e0e684531825 147 if((40 >= colour_data) && (colour_data <= 47))
thomasmorris 55:e0e684531825 148 {
thomasmorris 55:e0e684531825 149 temp_colour_data_5 = colour_data - 40;//Result shall be the colour
thomasmorris 55:e0e684531825 150 Cubelet_Colours[4] = temp_colour_data_5;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 151 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 152 }
thomasmorris 55:e0e684531825 153 if((48 >= colour_data) && (colour_data <= 55))
thomasmorris 55:e0e684531825 154 {
thomasmorris 55:e0e684531825 155 temp_colour_data_6 = colour_data - 48;//Result shall be the colour
thomasmorris 55:e0e684531825 156 Cubelet_Colours[5] = temp_colour_data_6;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 157 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 158 }
thomasmorris 55:e0e684531825 159 if((56 >= colour_data) && (colour_data <= 63))
thomasmorris 55:e0e684531825 160 {
thomasmorris 55:e0e684531825 161 temp_colour_data_7 = colour_data - 56;//Result shall be the colour
thomasmorris 55:e0e684531825 162 Cubelet_Colours[6] = temp_colour_data_7;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 163 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 164 }
thomasmorris 55:e0e684531825 165 if((64 >= colour_data) && (colour_data <= 71))
thomasmorris 55:e0e684531825 166 {
thomasmorris 55:e0e684531825 167 temp_colour_data_8 = colour_data - 64;//Result shall be the colour
thomasmorris 55:e0e684531825 168 Cubelet_Colours[7] = temp_colour_data_8;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 169 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 170 }
thomasmorris 55:e0e684531825 171 if((72 >= colour_data) && (colour_data <= 79))
thomasmorris 55:e0e684531825 172 {
thomasmorris 55:e0e684531825 173 temp_colour_data_9 = colour_data - 72;//Result shall be the colour
thomasmorris 55:e0e684531825 174 Cubelet_Colours[8] = temp_colour_data_9;//Stores the colour value to the mememory map
thomasmorris 55:e0e684531825 175 //take colour_data postion value and subtract it and you will be left with just the colour
thomasmorris 55:e0e684531825 176 }
thomasmorris 55:e0e684531825 177
thomasmorris 55:e0e684531825 178
thomasmorris 55:e0e684531825 179 if(Cubelet_Colours[5] == 1)//Store data to the white side
thomasmorris 54:a4c5949707ca 180 {
thomasmorris 54:a4c5949707ca 181 CubeMap[0][0][0] = convert(Cubelet_Colours[0]);
thomasmorris 54:a4c5949707ca 182 CubeMap[0][0][1] = convert(Cubelet_Colours[1]);
thomasmorris 54:a4c5949707ca 183 CubeMap[0][0][2] = convert(Cubelet_Colours[2]);
thomasmorris 54:a4c5949707ca 184 CubeMap[0][1][0] = convert(Cubelet_Colours[3]);
thomasmorris 54:a4c5949707ca 185 CubeMap[0][1][1] = convert(Cubelet_Colours[4]);
thomasmorris 54:a4c5949707ca 186 CubeMap[0][1][2] = convert(Cubelet_Colours[5]);
thomasmorris 54:a4c5949707ca 187 CubeMap[0][2][0] = convert(Cubelet_Colours[6]);
thomasmorris 54:a4c5949707ca 188 CubeMap[0][2][1] = convert(Cubelet_Colours[7]);
thomasmorris 54:a4c5949707ca 189 CubeMap[0][2][2] = convert(Cubelet_Colours[8]);
thomasmorris 55:e0e684531825 190 //Store this to the white face
thomasmorris 55:e0e684531825 191 }
thomasmorris 55:e0e684531825 192 if(Cubelet_Colours[5] == 2)//Store data to the orange side
thomasmorris 55:e0e684531825 193 {
thomasmorris 55:e0e684531825 194 CubeMap[1][0][0] = convert(Cubelet_Colours[0]);
thomasmorris 55:e0e684531825 195 CubeMap[1][0][1] = convert(Cubelet_Colours[1]);
thomasmorris 55:e0e684531825 196 CubeMap[1][0][2] = convert(Cubelet_Colours[2]);
thomasmorris 55:e0e684531825 197 CubeMap[1][1][0] = convert(Cubelet_Colours[3]);
thomasmorris 55:e0e684531825 198 CubeMap[1][1][1] = convert(Cubelet_Colours[4]);
thomasmorris 55:e0e684531825 199 CubeMap[1][1][2] = convert(Cubelet_Colours[5]);
thomasmorris 55:e0e684531825 200 CubeMap[1][2][0] = convert(Cubelet_Colours[6]);
thomasmorris 55:e0e684531825 201 CubeMap[1][2][1] = convert(Cubelet_Colours[7]);
thomasmorris 55:e0e684531825 202 CubeMap[1][2][2] = convert(Cubelet_Colours[8]);
thomasmorris 55:e0e684531825 203 //Store this to the white face
thomasmorris 55:e0e684531825 204 }
thomasmorris 55:e0e684531825 205 if(Cubelet_Colours[5] == 3)//Store data to the blue side
thomasmorris 55:e0e684531825 206 {
thomasmorris 55:e0e684531825 207 CubeMap[2][0][0] = convert(Cubelet_Colours[0]);
thomasmorris 55:e0e684531825 208 CubeMap[2][0][1] = convert(Cubelet_Colours[1]);
thomasmorris 55:e0e684531825 209 CubeMap[2][0][2] = convert(Cubelet_Colours[2]);
thomasmorris 55:e0e684531825 210 CubeMap[2][1][0] = convert(Cubelet_Colours[3]);
thomasmorris 55:e0e684531825 211 CubeMap[2][1][1] = convert(Cubelet_Colours[4]);
thomasmorris 55:e0e684531825 212 CubeMap[2][1][2] = convert(Cubelet_Colours[5]);
thomasmorris 55:e0e684531825 213 CubeMap[2][2][0] = convert(Cubelet_Colours[6]);
thomasmorris 55:e0e684531825 214 CubeMap[2][2][1] = convert(Cubelet_Colours[7]);
thomasmorris 55:e0e684531825 215 CubeMap[2][2][2] = convert(Cubelet_Colours[8]);
thomasmorris 54:a4c5949707ca 216 //Store this to the white face
thomasmorris 55:e0e684531825 217 }
thomasmorris 55:e0e684531825 218 if(Cubelet_Colours[5] == 4)//Store data to the red side
thomasmorris 55:e0e684531825 219 {
thomasmorris 55:e0e684531825 220 CubeMap[3][0][0] = convert(Cubelet_Colours[0]);
thomasmorris 55:e0e684531825 221 CubeMap[3][0][1] = convert(Cubelet_Colours[1]);
thomasmorris 55:e0e684531825 222 CubeMap[3][0][2] = convert(Cubelet_Colours[2]);
thomasmorris 55:e0e684531825 223 CubeMap[3][1][0] = convert(Cubelet_Colours[3]);
thomasmorris 55:e0e684531825 224 CubeMap[3][1][1] = convert(Cubelet_Colours[4]);
thomasmorris 55:e0e684531825 225 CubeMap[3][1][2] = convert(Cubelet_Colours[5]);
thomasmorris 55:e0e684531825 226 CubeMap[3][2][0] = convert(Cubelet_Colours[6]);
thomasmorris 55:e0e684531825 227 CubeMap[3][2][1] = convert(Cubelet_Colours[7]);
thomasmorris 55:e0e684531825 228 CubeMap[3][2][2] = convert(Cubelet_Colours[8]);
thomasmorris 55:e0e684531825 229 //Store this to the white face
thomasmorris 55:e0e684531825 230 }
thomasmorris 55:e0e684531825 231 if(Cubelet_Colours[5] == 5)//Store data to the green side
thomasmorris 55:e0e684531825 232 {
thomasmorris 55:e0e684531825 233 CubeMap[4][0][0] = convert(Cubelet_Colours[0]);
thomasmorris 55:e0e684531825 234 CubeMap[4][0][1] = convert(Cubelet_Colours[1]);
thomasmorris 55:e0e684531825 235 CubeMap[4][0][2] = convert(Cubelet_Colours[2]);
thomasmorris 55:e0e684531825 236 CubeMap[4][1][0] = convert(Cubelet_Colours[3]);
thomasmorris 55:e0e684531825 237 CubeMap[4][1][1] = convert(Cubelet_Colours[4]);
thomasmorris 55:e0e684531825 238 CubeMap[4][1][2] = convert(Cubelet_Colours[5]);
thomasmorris 55:e0e684531825 239 CubeMap[4][2][0] = convert(Cubelet_Colours[6]);
thomasmorris 55:e0e684531825 240 CubeMap[4][2][1] = convert(Cubelet_Colours[7]);
thomasmorris 55:e0e684531825 241 CubeMap[4][2][2] = convert(Cubelet_Colours[8]);
thomasmorris 55:e0e684531825 242 //Store this to the white face
thomasmorris 55:e0e684531825 243 }
thomasmorris 55:e0e684531825 244 if(Cubelet_Colours[5] == 6)//Store data to the yellow side
thomasmorris 55:e0e684531825 245 {
thomasmorris 55:e0e684531825 246 CubeMap[5][0][0] = convert(Cubelet_Colours[0]);
thomasmorris 55:e0e684531825 247 CubeMap[5][0][1] = convert(Cubelet_Colours[1]);
thomasmorris 55:e0e684531825 248 CubeMap[5][0][2] = convert(Cubelet_Colours[2]);
thomasmorris 55:e0e684531825 249 CubeMap[5][1][0] = convert(Cubelet_Colours[3]);
thomasmorris 55:e0e684531825 250 CubeMap[5][1][1] = convert(Cubelet_Colours[4]);
thomasmorris 55:e0e684531825 251 CubeMap[5][1][2] = convert(Cubelet_Colours[5]);
thomasmorris 55:e0e684531825 252 CubeMap[5][2][0] = convert(Cubelet_Colours[6]);
thomasmorris 55:e0e684531825 253 CubeMap[5][2][1] = convert(Cubelet_Colours[7]);
thomasmorris 55:e0e684531825 254 CubeMap[5][2][2] = convert(Cubelet_Colours[8]);
thomasmorris 55:e0e684531825 255 //Store this to the white face
thomasmorris 54:a4c5949707ca 256 }
thomasmorris 54:a4c5949707ca 257 }
thomasmorris 54:a4c5949707ca 258
thomasmorris 53:71f59e195f06 259 void Motor_Control()
thomasmorris 5:2594b953f111 260 {
thomasmorris 53:71f59e195f06 261 while(1)
thomasmorris 53:71f59e195f06 262 {
thomasmorris 53:71f59e195f06 263 if(Motor_To_Select !=0 and steps !=0)
thomasmorris 53:71f59e195f06 264 {
thomasmorris 53:71f59e195f06 265 if(Motor_To_Select == 1)
thomasmorris 53:71f59e195f06 266 {
thomasmorris 53:71f59e195f06 267 STEPPER_MOTOR_1.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 268 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 269 }
thomasmorris 53:71f59e195f06 270 else if(Motor_To_Select == 2)
thomasmorris 53:71f59e195f06 271 {
thomasmorris 53:71f59e195f06 272 STEPPER_MOTOR_2.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 273 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 274 }
thomasmorris 53:71f59e195f06 275 else if(Motor_To_Select == 3)
thomasmorris 53:71f59e195f06 276 {
thomasmorris 53:71f59e195f06 277 STEPPER_MOTOR_3.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 278 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 279 }
thomasmorris 53:71f59e195f06 280 else if(Motor_To_Select == 4)
thomasmorris 53:71f59e195f06 281 {
thomasmorris 53:71f59e195f06 282 STEPPER_MOTOR_4.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 283 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 284 }
thomasmorris 53:71f59e195f06 285 else if(Motor_To_Select == 5)
thomasmorris 53:71f59e195f06 286 {
thomasmorris 53:71f59e195f06 287 STEPPER_MOTOR_5.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 288 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 289 }
thomasmorris 53:71f59e195f06 290
thomasmorris 53:71f59e195f06 291 else if(Motor_To_Select == 6)
thomasmorris 53:71f59e195f06 292 {
thomasmorris 53:71f59e195f06 293 STEPPER_MOTOR_6.Rotate_Steps(steps ,direction);
thomasmorris 53:71f59e195f06 294 //Motor_To_Select = 0;
thomasmorris 53:71f59e195f06 295 }
thomasmorris 53:71f59e195f06 296
thomasmorris 53:71f59e195f06 297 }
thomasmorris 53:71f59e195f06 298 }
thomasmorris 25:36699ed589ab 299 }
thomasmorris 53:71f59e195f06 300
thomasmorris 25:36699ed589ab 301 int main()
thomasmorris 25:36699ed589ab 302 {
thomasmorris 52:99915f5240b2 303 pc.baud(9600); //Sets the Serial Comms Baud Rate
thomasmorris 53:71f59e195f06 304 //SPI_INIT();
thomasmorris 53:71f59e195f06 305 cs = 1; //Active Low
thomasmorris 53:71f59e195f06 306
thomasmorris 53:71f59e195f06 307 // Setup the spi for 8 bit data, high steady state clock,
thomasmorris 53:71f59e195f06 308 // second edge capture, with a 1MHz clock rate
thomasmorris 55:e0e684531825 309 spi.format(16,1); // 8 Data bits phase 0 polarity 0 //CHECK THIS
thomasmorris 53:71f59e195f06 310 spi.frequency(1000000);//Output clock frequency 1Mhz
thomasmorris 53:71f59e195f06 311 //post(); //Power on Self Test
thomasmorris 25:36699ed589ab 312
thomasmorris 52:99915f5240b2 313 //Start Threads
thomasmorris 53:71f59e195f06 314 t1.start(Motor_Control);
thomasmorris 53:71f59e195f06 315 t2.start(SPI_INTERFACE);
thomasmorris 53:71f59e195f06 316 t3.start(Serial_Commands);
thomasmorris 52:99915f5240b2 317 //Interrupts
thomasmorris 52:99915f5240b2 318 SW1.fall(&SW1FallingEdge);
thomasmorris 52:99915f5240b2 319 SW2.fall(&SW2FallingEdge);
thomasmorris 52:99915f5240b2 320
thomasmorris 5:2594b953f111 321 //Main thread ID
thomasmorris 5:2594b953f111 322 idMain = osThreadGetId(); //CMSIS RTOS call
thomasmorris 25:36699ed589ab 323
thomasmorris 53:71f59e195f06 324
thomasmorris 5:2594b953f111 325 //Thread ID
thomasmorris 5:2594b953f111 326 id1 = t1.gettid();
thomasmorris 5:2594b953f111 327 id2 = t2.gettid();
thomasmorris 21:3c078c799caa 328 id3 = t3.gettid();
thomasmorris 21:3c078c799caa 329 id4 = t4.gettid();
chills 24:7d2da96e05ad 330 id5 = t5.gettid();
thomasmorris 48:244d6d81bb52 331 id6 = t6.gettid();
thomasmorris 53:71f59e195f06 332
thomasmorris 48:244d6d81bb52 333 while(true)
thomasmorris 48:244d6d81bb52 334 {
thomasmorris 53:71f59e195f06 335 //Do nothing main thread will sleep
noutram 0:36e89e3ed7c4 336 }
thomasmorris 45:875f7e18a386 337 }