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.
main.cpp@3:7e568908f1c4, 2015-05-01 (annotated)
- Committer:
- martydd3
- Date:
- Fri May 01 01:43:57 2015 +0000
- Revision:
- 3:7e568908f1c4
- Parent:
- 2:4b42ccb9df8d
- Child:
- 4:75498bd2e742
Cartesian lines working, decided to get rid of polar lines
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| martydd3 | 0:b654a906fb40 | 1 | #include "mbed.h" |
| martydd3 | 0:b654a906fb40 | 2 | #include "MRF24J40.h" |
| martydd3 | 0:b654a906fb40 | 3 | |
| martydd3 | 0:b654a906fb40 | 4 | #include <string> |
| martydd3 | 0:b654a906fb40 | 5 | #include "constants.h" |
| martydd3 | 0:b654a906fb40 | 6 | #include "shape.h" |
| martydd3 | 0:b654a906fb40 | 7 | |
| martydd3 | 0:b654a906fb40 | 8 | // RF tranceiver to link with handheld. |
| martydd3 | 0:b654a906fb40 | 9 | MRF24J40 mrf(p11, p12, p13, p14, p26); |
| martydd3 | 0:b654a906fb40 | 10 | |
| martydd3 | 0:b654a906fb40 | 11 | // LEDs you can treat these as variables (led2 = 1 will turn led2 on!) |
| martydd3 | 0:b654a906fb40 | 12 | DigitalOut led1(LED1); |
| martydd3 | 0:b654a906fb40 | 13 | DigitalOut led2(LED2); |
| martydd3 | 0:b654a906fb40 | 14 | DigitalOut led3(LED3); |
| martydd3 | 0:b654a906fb40 | 15 | DigitalOut led4(LED4); |
| martydd3 | 0:b654a906fb40 | 16 | |
| martydd3 | 0:b654a906fb40 | 17 | // Timer |
| martydd3 | 0:b654a906fb40 | 18 | Timer timer; |
| martydd3 | 0:b654a906fb40 | 19 | |
| martydd3 | 0:b654a906fb40 | 20 | // Serial port for showing RX data. |
| martydd3 | 0:b654a906fb40 | 21 | Serial pc(USBTX, USBRX); |
| martydd3 | 0:b654a906fb40 | 22 | |
| martydd3 | 0:b654a906fb40 | 23 | // Used for sending and receiving |
| martydd3 | 0:b654a906fb40 | 24 | char txBuffer[128]; |
| martydd3 | 0:b654a906fb40 | 25 | char rxBuffer[128]; |
| martydd3 | 0:b654a906fb40 | 26 | int rxLen; |
| martydd3 | 0:b654a906fb40 | 27 | |
| martydd3 | 0:b654a906fb40 | 28 | //***************** Do not change these methods (please) *****************// |
| martydd3 | 0:b654a906fb40 | 29 | |
| martydd3 | 0:b654a906fb40 | 30 | /** |
| martydd3 | 0:b654a906fb40 | 31 | * Receive data from the MRF24J40. |
| martydd3 | 0:b654a906fb40 | 32 | * |
| martydd3 | 0:b654a906fb40 | 33 | * @param data A pointer to a char array to hold the data |
| martydd3 | 0:b654a906fb40 | 34 | * @param maxLength The max amount of data to read. |
| martydd3 | 0:b654a906fb40 | 35 | */ |
| martydd3 | 0:b654a906fb40 | 36 | int rf_receive(char *data, uint8_t maxLength) |
| martydd3 | 0:b654a906fb40 | 37 | { |
| martydd3 | 0:b654a906fb40 | 38 | uint8_t len = mrf.Receive((uint8_t *)data, maxLength); |
| martydd3 | 0:b654a906fb40 | 39 | uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00}; |
| martydd3 | 0:b654a906fb40 | 40 | |
| martydd3 | 0:b654a906fb40 | 41 | if(len > 10) { |
| martydd3 | 0:b654a906fb40 | 42 | //Remove the header and footer of the message |
| martydd3 | 0:b654a906fb40 | 43 | for(uint8_t i = 0; i < len-2; i++) { |
| martydd3 | 0:b654a906fb40 | 44 | if(i<8) { |
| martydd3 | 0:b654a906fb40 | 45 | //Make sure our header is valid first |
| martydd3 | 0:b654a906fb40 | 46 | if(data[i] != header[i]) |
| martydd3 | 0:b654a906fb40 | 47 | return 0; |
| martydd3 | 0:b654a906fb40 | 48 | } else { |
| martydd3 | 0:b654a906fb40 | 49 | data[i-8] = data[i]; |
| martydd3 | 0:b654a906fb40 | 50 | } |
| martydd3 | 0:b654a906fb40 | 51 | } |
| martydd3 | 0:b654a906fb40 | 52 | |
| martydd3 | 0:b654a906fb40 | 53 | //pc.printf("Received: %s length:%d\r\n", data, ((int)len)-10); |
| martydd3 | 0:b654a906fb40 | 54 | } |
| martydd3 | 0:b654a906fb40 | 55 | return ((int)len)-10; |
| martydd3 | 0:b654a906fb40 | 56 | } |
| martydd3 | 0:b654a906fb40 | 57 | |
| martydd3 | 0:b654a906fb40 | 58 | /** |
| martydd3 | 0:b654a906fb40 | 59 | * Send data to another MRF24J40. |
| martydd3 | 0:b654a906fb40 | 60 | * |
| martydd3 | 0:b654a906fb40 | 61 | * @param data The string to send |
| martydd3 | 0:b654a906fb40 | 62 | * @param maxLength The length of the data to send. |
| martydd3 | 0:b654a906fb40 | 63 | * If you are sending a null-terminated string you can pass strlen(data)+1 |
| martydd3 | 0:b654a906fb40 | 64 | */ |
| martydd3 | 0:b654a906fb40 | 65 | void rf_send(char *data, uint8_t len) |
| martydd3 | 0:b654a906fb40 | 66 | { |
| martydd3 | 0:b654a906fb40 | 67 | //We need to prepend the message with a valid ZigBee header |
| martydd3 | 0:b654a906fb40 | 68 | uint8_t header[8]= {1, 8, 0, 0xA1, 0xB2, 0xC3, 0xD4, 0x00}; |
| martydd3 | 0:b654a906fb40 | 69 | uint8_t *send_buf = (uint8_t *) malloc( sizeof(uint8_t) * (len+8) ); |
| martydd3 | 0:b654a906fb40 | 70 | |
| martydd3 | 0:b654a906fb40 | 71 | for(uint8_t i = 0; i < len+8; i++) { |
| martydd3 | 0:b654a906fb40 | 72 | //prepend the 8-byte header |
| martydd3 | 0:b654a906fb40 | 73 | send_buf[i] = (i<8) ? header[i] : data[i-8]; |
| martydd3 | 0:b654a906fb40 | 74 | } |
| martydd3 | 0:b654a906fb40 | 75 | //pc.printf("Sent: %s\r\n", send_buf+8); |
| martydd3 | 0:b654a906fb40 | 76 | |
| martydd3 | 0:b654a906fb40 | 77 | mrf.Send(send_buf, len+8); |
| martydd3 | 0:b654a906fb40 | 78 | free(send_buf); |
| martydd3 | 0:b654a906fb40 | 79 | } |
| martydd3 | 0:b654a906fb40 | 80 | |
| martydd3 | 2:4b42ccb9df8d | 81 | /*******************************************************************/ |
| martydd3 | 2:4b42ccb9df8d | 82 | // Display interrupt and drivers |
| martydd3 | 2:4b42ccb9df8d | 83 | |
| martydd3 | 2:4b42ccb9df8d | 84 | int frame_id = 0; |
| martydd3 | 2:4b42ccb9df8d | 85 | char frame_buffer1[SLICES][WIDTH]; |
| martydd3 | 2:4b42ccb9df8d | 86 | char frame_buffer2[SLICES][WIDTH]; |
| martydd3 | 0:b654a906fb40 | 87 | char work_buffer[SLICES][WIDTH]; |
| martydd3 | 0:b654a906fb40 | 88 | |
| martydd3 | 2:4b42ccb9df8d | 89 | int slice_i = 100; |
| martydd3 | 0:b654a906fb40 | 90 | BusOut blade(p15, p16, p17, p18, p19, p20, p21, p22); |
| martydd3 | 0:b654a906fb40 | 91 | DigitalOut clk(p23); |
| martydd3 | 0:b654a906fb40 | 92 | DigitalOut disp(p24); |
| martydd3 | 0:b654a906fb40 | 93 | Ticker pixel_ticker; |
| martydd3 | 0:b654a906fb40 | 94 | |
| martydd3 | 2:4b42ccb9df8d | 95 | void push_pixels(){ |
| martydd3 | 2:4b42ccb9df8d | 96 | for(int j = 8; j < WIDTH; j++){ |
| martydd3 | 2:4b42ccb9df8d | 97 | if(frame_id == 0) |
| martydd3 | 2:4b42ccb9df8d | 98 | blade = frame_buffer1[slice_i][j]; |
| martydd3 | 2:4b42ccb9df8d | 99 | else |
| martydd3 | 2:4b42ccb9df8d | 100 | blade = frame_buffer2[slice_i][j]; |
| martydd3 | 2:4b42ccb9df8d | 101 | |
| martydd3 | 2:4b42ccb9df8d | 102 | clk = 1; |
| martydd3 | 2:4b42ccb9df8d | 103 | clk = 0; |
| martydd3 | 2:4b42ccb9df8d | 104 | } |
| martydd3 | 2:4b42ccb9df8d | 105 | |
| martydd3 | 2:4b42ccb9df8d | 106 | for(int j = 7; j >= 0; j--){ |
| martydd3 | 2:4b42ccb9df8d | 107 | if(frame_id == 0) |
| martydd3 | 2:4b42ccb9df8d | 108 | blade = frame_buffer1[slice_i][j]; |
| martydd3 | 2:4b42ccb9df8d | 109 | else |
| martydd3 | 2:4b42ccb9df8d | 110 | blade = frame_buffer2[slice_i][j]; |
| martydd3 | 2:4b42ccb9df8d | 111 | |
| martydd3 | 2:4b42ccb9df8d | 112 | clk = 1; |
| martydd3 | 2:4b42ccb9df8d | 113 | clk = 0; |
| martydd3 | 2:4b42ccb9df8d | 114 | } |
| martydd3 | 2:4b42ccb9df8d | 115 | |
| martydd3 | 2:4b42ccb9df8d | 116 | disp = 1; |
| martydd3 | 2:4b42ccb9df8d | 117 | disp = 0; |
| martydd3 | 2:4b42ccb9df8d | 118 | |
| martydd3 | 2:4b42ccb9df8d | 119 | slice_i = (slice_i + 1)%SLICES; |
| martydd3 | 2:4b42ccb9df8d | 120 | } |
| martydd3 | 2:4b42ccb9df8d | 121 | |
| martydd3 | 2:4b42ccb9df8d | 122 | //Hall sensor interupt |
| martydd3 | 2:4b42ccb9df8d | 123 | double rotate_time; |
| martydd3 | 2:4b42ccb9df8d | 124 | double slice_time; |
| martydd3 | 2:4b42ccb9df8d | 125 | |
| martydd3 | 2:4b42ccb9df8d | 126 | Timer hall_timer; |
| martydd3 | 2:4b42ccb9df8d | 127 | |
| martydd3 | 2:4b42ccb9df8d | 128 | void rotate_sense(){ |
| martydd3 | 2:4b42ccb9df8d | 129 | static bool firstTime = false; |
| martydd3 | 2:4b42ccb9df8d | 130 | |
| martydd3 | 2:4b42ccb9df8d | 131 | if (firstTime){ |
| martydd3 | 2:4b42ccb9df8d | 132 | hall_timer.reset(); |
| martydd3 | 2:4b42ccb9df8d | 133 | hall_timer.start(); |
| martydd3 | 2:4b42ccb9df8d | 134 | firstTime = false; |
| martydd3 | 2:4b42ccb9df8d | 135 | return; |
| martydd3 | 2:4b42ccb9df8d | 136 | } |
| martydd3 | 2:4b42ccb9df8d | 137 | |
| martydd3 | 2:4b42ccb9df8d | 138 | rotate_time = hall_timer.read_us(); |
| martydd3 | 2:4b42ccb9df8d | 139 | hall_timer.reset(); |
| martydd3 | 2:4b42ccb9df8d | 140 | hall_timer.start(); |
| martydd3 | 2:4b42ccb9df8d | 141 | |
| martydd3 | 2:4b42ccb9df8d | 142 | slice_time = (double) rotate_time/SLICES; |
| martydd3 | 2:4b42ccb9df8d | 143 | slice_i = 0; |
| martydd3 | 2:4b42ccb9df8d | 144 | pixel_ticker.attach_us(&push_pixels, slice_time); |
| martydd3 | 2:4b42ccb9df8d | 145 | } |
| martydd3 | 2:4b42ccb9df8d | 146 | |
| martydd3 | 2:4b42ccb9df8d | 147 | /***************************************************************/ |
| martydd3 | 2:4b42ccb9df8d | 148 | //code to adjust for offset blades and vertical alignment |
| martydd3 | 2:4b42ccb9df8d | 149 | |
| martydd3 | 0:b654a906fb40 | 150 | int displaces[HEIGHT]; |
| martydd3 | 0:b654a906fb40 | 151 | |
| martydd3 | 0:b654a906fb40 | 152 | void init_displaces(){ |
| martydd3 | 0:b654a906fb40 | 153 | for(int i = 0; i < HEIGHT; i++){ |
| martydd3 | 0:b654a906fb40 | 154 | switch(i){ |
| martydd3 | 0:b654a906fb40 | 155 | case 0: displaces[i] = 0; break; |
| martydd3 | 0:b654a906fb40 | 156 | case 1: displaces[i] = 4 * SLICES / 8; break; |
| martydd3 | 0:b654a906fb40 | 157 | case 2: displaces[i] = 7 * SLICES / 8 - 5; break; |
| martydd3 | 0:b654a906fb40 | 158 | case 3: displaces[i] = 3 * SLICES / 8 - 8; break; |
| martydd3 | 0:b654a906fb40 | 159 | case 4: displaces[i] = 6 * SLICES / 8 - 6; break; |
| martydd3 | 0:b654a906fb40 | 160 | case 5: displaces[i] = 2 * SLICES / 8 - 7; break; |
| martydd3 | 0:b654a906fb40 | 161 | case 6: displaces[i] = 5 * SLICES / 8 - 7; break; |
| martydd3 | 0:b654a906fb40 | 162 | case 7: displaces[i] = 1 * SLICES / 8 - 8; break; |
| martydd3 | 0:b654a906fb40 | 163 | } |
| martydd3 | 0:b654a906fb40 | 164 | } |
| martydd3 | 0:b654a906fb40 | 165 | } |
| martydd3 | 0:b654a906fb40 | 166 | |
| martydd3 | 0:b654a906fb40 | 167 | void convert_array(){ |
| martydd3 | 2:4b42ccb9df8d | 168 | static bool initialized = false; |
| martydd3 | 0:b654a906fb40 | 169 | int array_i; |
| martydd3 | 0:b654a906fb40 | 170 | |
| martydd3 | 2:4b42ccb9df8d | 171 | if(!initialized){ |
| martydd3 | 2:4b42ccb9df8d | 172 | init_displaces(); |
| martydd3 | 2:4b42ccb9df8d | 173 | } |
| martydd3 | 0:b654a906fb40 | 174 | |
| martydd3 | 0:b654a906fb40 | 175 | for(int i = 0; i < SLICES; i++){ |
| martydd3 | 0:b654a906fb40 | 176 | for(int j = 0; j < WIDTH; j++){ |
| martydd3 | 0:b654a906fb40 | 177 | char bit = 0x00; |
| martydd3 | 0:b654a906fb40 | 178 | |
| martydd3 | 0:b654a906fb40 | 179 | for(int h = 0; h < HEIGHT; h++){ |
| martydd3 | 0:b654a906fb40 | 180 | bit |= (work_buffer[(i + displaces[h]) % SLICES][j] & (0x01 << h)); |
| martydd3 | 0:b654a906fb40 | 181 | } |
| martydd3 | 0:b654a906fb40 | 182 | |
| martydd3 | 2:4b42ccb9df8d | 183 | if(frame_id == 0) |
| martydd3 | 2:4b42ccb9df8d | 184 | frame_buffer2[i][j] = bit; |
| martydd3 | 2:4b42ccb9df8d | 185 | else |
| martydd3 | 2:4b42ccb9df8d | 186 | frame_buffer1[i][j] = bit; |
| martydd3 | 0:b654a906fb40 | 187 | } |
| martydd3 | 0:b654a906fb40 | 188 | } |
| martydd3 | 0:b654a906fb40 | 189 | |
| martydd3 | 2:4b42ccb9df8d | 190 | if(frame_id == 0) |
| martydd3 | 2:4b42ccb9df8d | 191 | frame_id = 1; |
| martydd3 | 2:4b42ccb9df8d | 192 | else |
| martydd3 | 2:4b42ccb9df8d | 193 | frame_id = 0; |
| martydd3 | 2:4b42ccb9df8d | 194 | } |
| martydd3 | 2:4b42ccb9df8d | 195 | |
| martydd3 | 2:4b42ccb9df8d | 196 | int display_mode = 0; |
| martydd3 | 2:4b42ccb9df8d | 197 | Ticker animate_ticker; |
| martydd3 | 2:4b42ccb9df8d | 198 | void animate(){ |
| martydd3 | 2:4b42ccb9df8d | 199 | static WaveCircle *wc1 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 200 | static WaveCircle *wc2 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 201 | static WaveCircle *wc3 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 202 | static WaveCircle *wc4 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 203 | static WaveCircle *wc5 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 204 | static WaveCircle *wc6 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 205 | static WaveCircle *wc7 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 206 | static WaveCircle *wc8 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 207 | static WaveCircle *wc9 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 208 | static WaveCircle *wc10 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 209 | static WaveCircle *wc11 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 210 | static WaveCircle *wc12 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 211 | static WaveCircle *wc13 = NULL; |
| martydd3 | 2:4b42ccb9df8d | 212 | |
| martydd3 | 2:4b42ccb9df8d | 213 | for(int i = 0; i < SLICES; i++){ |
| martydd3 | 2:4b42ccb9df8d | 214 | for(int j = 0; j < WIDTH; j++){ |
| martydd3 | 2:4b42ccb9df8d | 215 | work_buffer[i][j] = 0x00; |
| martydd3 | 2:4b42ccb9df8d | 216 | } |
| martydd3 | 2:4b42ccb9df8d | 217 | } |
| martydd3 | 2:4b42ccb9df8d | 218 | |
| martydd3 | 2:4b42ccb9df8d | 219 | if(display_mode == 1) |
| martydd3 | 2:4b42ccb9df8d | 220 | { |
| martydd3 | 2:4b42ccb9df8d | 221 | if(wc1 == NULL){ |
| martydd3 | 2:4b42ccb9df8d | 222 | wc1 = new WaveCircle(3, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 223 | wc2 = new WaveCircle(4, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 224 | wc3 = new WaveCircle(5, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 225 | wc4 = new WaveCircle(6, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 226 | wc5 = new WaveCircle(7, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 227 | wc6 = new WaveCircle(8, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 228 | wc7 = new WaveCircle(9, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 229 | wc8 = new WaveCircle(10, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 230 | wc9 = new WaveCircle(11, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 231 | wc10 = new WaveCircle(12, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 232 | wc11 = new WaveCircle(13, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 233 | wc12 = new WaveCircle(14, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 234 | wc13 = new WaveCircle(15, 4, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 235 | } |
| martydd3 | 2:4b42ccb9df8d | 236 | |
| martydd3 | 2:4b42ccb9df8d | 237 | wc1->animate(); |
| martydd3 | 2:4b42ccb9df8d | 238 | wc2->animate(); |
| martydd3 | 2:4b42ccb9df8d | 239 | wc3->animate(); |
| martydd3 | 2:4b42ccb9df8d | 240 | wc4->animate(); |
| martydd3 | 2:4b42ccb9df8d | 241 | wc5->animate(); |
| martydd3 | 2:4b42ccb9df8d | 242 | wc6->animate(); |
| martydd3 | 2:4b42ccb9df8d | 243 | wc7->animate(); |
| martydd3 | 2:4b42ccb9df8d | 244 | wc8->animate(); |
| martydd3 | 2:4b42ccb9df8d | 245 | wc9->animate(); |
| martydd3 | 2:4b42ccb9df8d | 246 | wc10->animate(); |
| martydd3 | 2:4b42ccb9df8d | 247 | wc11->animate(); |
| martydd3 | 2:4b42ccb9df8d | 248 | wc12->animate(); |
| martydd3 | 2:4b42ccb9df8d | 249 | wc13->animate(); |
| martydd3 | 2:4b42ccb9df8d | 250 | |
| martydd3 | 2:4b42ccb9df8d | 251 | wc1->draw(); |
| martydd3 | 2:4b42ccb9df8d | 252 | wc2->draw(); |
| martydd3 | 2:4b42ccb9df8d | 253 | wc3->draw(); |
| martydd3 | 2:4b42ccb9df8d | 254 | wc4->draw(); |
| martydd3 | 2:4b42ccb9df8d | 255 | wc5->draw(); |
| martydd3 | 2:4b42ccb9df8d | 256 | wc6->draw(); |
| martydd3 | 2:4b42ccb9df8d | 257 | wc7->draw(); |
| martydd3 | 2:4b42ccb9df8d | 258 | wc8->draw(); |
| martydd3 | 2:4b42ccb9df8d | 259 | wc9->draw(); |
| martydd3 | 2:4b42ccb9df8d | 260 | wc10->draw(); |
| martydd3 | 2:4b42ccb9df8d | 261 | wc11->draw(); |
| martydd3 | 2:4b42ccb9df8d | 262 | wc12->draw(); |
| martydd3 | 2:4b42ccb9df8d | 263 | wc13->draw(); |
| martydd3 | 2:4b42ccb9df8d | 264 | } |
| martydd3 | 2:4b42ccb9df8d | 265 | else if(display_mode == 2) |
| martydd3 | 2:4b42ccb9df8d | 266 | { |
| martydd3 | 2:4b42ccb9df8d | 267 | // Eight sided star |
| martydd3 | 2:4b42ccb9df8d | 268 | Line line1(15, 0, 0, 15, 90, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 269 | Line line2(15, 90, 7, 15, 180, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 270 | Line line3(15, 180, 0, 15, 270, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 271 | Line line4(15, 270, 7, 15, 0, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 272 | line1.draw(); |
| martydd3 | 2:4b42ccb9df8d | 273 | line2.draw(); |
| martydd3 | 2:4b42ccb9df8d | 274 | line3.draw(); |
| martydd3 | 2:4b42ccb9df8d | 275 | line4.draw(); |
| martydd3 | 2:4b42ccb9df8d | 276 | |
| martydd3 | 2:4b42ccb9df8d | 277 | Line line5(15, 45, 0, 15, 135, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 278 | Line line6(15, 135, 7, 15, 225, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 279 | Line line7(15, 225, 0, 15, 315, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 280 | Line line8(15, 315, 7, 15, 45, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 281 | line5.draw(); |
| martydd3 | 2:4b42ccb9df8d | 282 | line6.draw(); |
| martydd3 | 2:4b42ccb9df8d | 283 | line7.draw(); |
| martydd3 | 2:4b42ccb9df8d | 284 | line8.draw(); |
| martydd3 | 2:4b42ccb9df8d | 285 | } |
| martydd3 | 2:4b42ccb9df8d | 286 | else if(display_mode == 3) |
| martydd3 | 2:4b42ccb9df8d | 287 | { |
| martydd3 | 2:4b42ccb9df8d | 288 | Line line1(1, 0, 0, 1, 0, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 289 | Line line2(9, 35, 0, 9, 35, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 290 | Line line3(9, 325, 0, 9, 325, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 291 | Line line4(13, 0, 0, 13, 0, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 292 | |
| martydd3 | 2:4b42ccb9df8d | 293 | line1.draw(); |
| martydd3 | 2:4b42ccb9df8d | 294 | line2.draw(); |
| martydd3 | 2:4b42ccb9df8d | 295 | line3.draw(); |
| martydd3 | 2:4b42ccb9df8d | 296 | line4.draw(); |
| martydd3 | 2:4b42ccb9df8d | 297 | |
| martydd3 | 2:4b42ccb9df8d | 298 | Line line5(M_PI * 320 / 180, 0.777030, 0, 0, 35, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 299 | Line line6(M_PI * 40 / 180, 0.777030, 0, 0, 325, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 300 | Line line7(M_PI * 320 / 180, 8.787681, 325, 0, 0, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 301 | Line line8(M_PI * 40 / 180, 8.787681, 35, 0, 0, 0, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 302 | |
| martydd3 | 2:4b42ccb9df8d | 303 | line5.draw(); |
| martydd3 | 2:4b42ccb9df8d | 304 | line6.draw(); |
| martydd3 | 2:4b42ccb9df8d | 305 | line7.draw(); |
| martydd3 | 2:4b42ccb9df8d | 306 | line8.draw(); |
| martydd3 | 2:4b42ccb9df8d | 307 | |
| martydd3 | 2:4b42ccb9df8d | 308 | Line line9(M_PI * 320 / 180, 0.777030, 0, 7, 35, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 309 | Line line10(M_PI * 40 / 180, 0.777030, 0, 7, 325, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 310 | Line line11(M_PI * 320 / 180, 8.787681, 325, 7, 0, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 311 | Line line12(M_PI * 40 / 180, 8.787681, 35, 7, 0, 7, &work_buffer); |
| martydd3 | 2:4b42ccb9df8d | 312 | |
| martydd3 | 2:4b42ccb9df8d | 313 | line9.draw(); |
| martydd3 | 2:4b42ccb9df8d | 314 | line10.draw(); |
| martydd3 | 2:4b42ccb9df8d | 315 | line11.draw(); |
| martydd3 | 2:4b42ccb9df8d | 316 | line12.draw(); |
| martydd3 | 2:4b42ccb9df8d | 317 | } else if(display_mode == 4){ |
| martydd3 | 3:7e568908f1c4 | 318 | CartLine line1(0, 16, 0, 0, -16, 7, &work_buffer); |
| martydd3 | 3:7e568908f1c4 | 319 | CartLine line2(4, 16, 0, 4, -16, 7, &work_buffer); |
| martydd3 | 3:7e568908f1c4 | 320 | CartLine line3(8, 16, 0, 8, -16, 7, &work_buffer); |
| martydd3 | 3:7e568908f1c4 | 321 | CartLine line4(12, 16, 0, 12, -16, 7, &work_buffer); |
| martydd3 | 3:7e568908f1c4 | 322 | CartLine line5(-4, 16, 0, -4, -16, 7, &work_buffer); |
| martydd3 | 3:7e568908f1c4 | 323 | CartLine line6(-8, 16, 0, -8, -16, 7, &work_buffer); |
| martydd3 | 3:7e568908f1c4 | 324 | CartLine line7(-12, 16, 0, -12, -16, 7, &work_buffer); |
| martydd3 | 3:7e568908f1c4 | 325 | |
| martydd3 | 3:7e568908f1c4 | 326 | |
| martydd3 | 2:4b42ccb9df8d | 327 | |
| martydd3 | 2:4b42ccb9df8d | 328 | line1.draw(); |
| martydd3 | 2:4b42ccb9df8d | 329 | line2.draw(); |
| martydd3 | 2:4b42ccb9df8d | 330 | line3.draw(); |
| martydd3 | 2:4b42ccb9df8d | 331 | line4.draw(); |
| martydd3 | 2:4b42ccb9df8d | 332 | line5.draw(); |
| martydd3 | 2:4b42ccb9df8d | 333 | line6.draw(); |
| martydd3 | 2:4b42ccb9df8d | 334 | line7.draw(); |
| martydd3 | 2:4b42ccb9df8d | 335 | } |
| martydd3 | 2:4b42ccb9df8d | 336 | |
| martydd3 | 2:4b42ccb9df8d | 337 | convert_array(); |
| martydd3 | 2:4b42ccb9df8d | 338 | } |
| martydd3 | 2:4b42ccb9df8d | 339 | |
| martydd3 | 2:4b42ccb9df8d | 340 | bool animate_i = false; |
| martydd3 | 2:4b42ccb9df8d | 341 | void animate_int(){ |
| martydd3 | 2:4b42ccb9df8d | 342 | animate_i = true; |
| martydd3 | 0:b654a906fb40 | 343 | } |
| martydd3 | 0:b654a906fb40 | 344 | |
| martydd3 | 0:b654a906fb40 | 345 | int main (void) |
| martydd3 | 0:b654a906fb40 | 346 | { |
| martydd3 | 2:4b42ccb9df8d | 347 | display_mode = 4; |
| martydd3 | 2:4b42ccb9df8d | 348 | |
| martydd3 | 0:b654a906fb40 | 349 | InterruptIn hall_pin(p25); |
| martydd3 | 0:b654a906fb40 | 350 | hall_pin.fall(&rotate_sense); |
| martydd3 | 2:4b42ccb9df8d | 351 | animate_ticker.attach(&animate_int, 3.0); |
| martydd3 | 0:b654a906fb40 | 352 | |
| martydd3 | 0:b654a906fb40 | 353 | uint8_t channel = 2; |
| martydd3 | 0:b654a906fb40 | 354 | |
| martydd3 | 0:b654a906fb40 | 355 | //Set the Channel. 0 is default, 15 is max |
| martydd3 | 0:b654a906fb40 | 356 | mrf.SetChannel(channel); |
| martydd3 | 0:b654a906fb40 | 357 | |
| martydd3 | 0:b654a906fb40 | 358 | while(true) { |
| martydd3 | 2:4b42ccb9df8d | 359 | if(animate_i){ |
| martydd3 | 2:4b42ccb9df8d | 360 | animate(); |
| martydd3 | 2:4b42ccb9df8d | 361 | } |
| martydd3 | 0:b654a906fb40 | 362 | } |
| martydd3 | 0:b654a906fb40 | 363 | } |