pls work
Dependencies: mbed WS2813 PixelArray SDFileSystem ds3231
Fork of SDFileSystem_HelloWorld by
main.cpp@27:2b989633a518, 2019-01-15 (annotated)
- Committer:
- LukevdBurg
- Date:
- Tue Jan 15 13:05:29 2019 +0000
- Revision:
- 27:2b989633a518
- Parent:
- 26:dcced86ba984
Test Code cu
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
neilt6 | 0:8f2b6eed2a9d | 1 | #include "mbed.h" |
LukevdBurg | 27:2b989633a518 | 2 | #include "WS2812.h" |
LukevdBurg | 27:2b989633a518 | 3 | #include "PixelArray.h" |
neilt6 | 0:8f2b6eed2a9d | 4 | #include "SDFileSystem.h" |
LukevdBurg | 27:2b989633a518 | 5 | #include <ds3231.h> |
neilt6 | 0:8f2b6eed2a9d | 6 | |
LukevdBurg | 27:2b989633a518 | 7 | #define WS2812_BUF 32 |
LukevdBurg | 27:2b989633a518 | 8 | #define NUM_COLORS 7 |
LukevdBurg | 27:2b989633a518 | 9 | #define NUM_LEDS_PER_COLOR 32 |
LukevdBurg | 27:2b989633a518 | 10 | |
LukevdBurg | 27:2b989633a518 | 11 | PixelArray px(WS2812_BUF); |
LukevdBurg | 27:2b989633a518 | 12 | WS2812 ws(PB_9, WS2812_BUF, 10, 36, 20, 36); |
LukevdBurg | 27:2b989633a518 | 13 | |
LukevdBurg | 27:2b989633a518 | 14 | Ds3231 rtc(PB_7, PB_8); |
LukevdBurg | 27:2b989633a518 | 15 | |
deldering95 | 26:dcced86ba984 | 16 | SDFileSystem sd(PC_12,PC_11,PC_10,PA_15, "sd", NC, SDFileSystem::SWITCH_NONE, 400000); |
deldering95 | 26:dcced86ba984 | 17 | RawSerial pc(PA_9,PA_10); |
LukevdBurg | 27:2b989633a518 | 18 | |
LukevdBurg | 27:2b989633a518 | 19 | int i = 0; |
LukevdBurg | 27:2b989633a518 | 20 | int r,g,b,y,w; |
LukevdBurg | 27:2b989633a518 | 21 | |
LukevdBurg | 27:2b989633a518 | 22 | AnalogIn analog_value(PC_0); |
LukevdBurg | 27:2b989633a518 | 23 | float meas; |
neilt6 | 10:ae649a596123 | 24 | |
LukevdBurg | 27:2b989633a518 | 25 | DigitalOut Led0 (PA_4); |
LukevdBurg | 27:2b989633a518 | 26 | DigitalOut Led1 (PA_5); |
LukevdBurg | 27:2b989633a518 | 27 | DigitalOut Led2 (PA_6); |
LukevdBurg | 27:2b989633a518 | 28 | DigitalOut Led3 (PA_7); |
LukevdBurg | 27:2b989633a518 | 29 | DigitalOut Led4 (PC_4); |
neilt6 | 10:ae649a596123 | 30 | |
LukevdBurg | 27:2b989633a518 | 31 | ds3231_time_t Time = {12, 0, 0, 1, 0}; |
LukevdBurg | 27:2b989633a518 | 32 | uint16_t rtn_val; |
LukevdBurg | 27:2b989633a518 | 33 | uint32_t SetTime; |
LukevdBurg | 27:2b989633a518 | 34 | uint32_t GetTime; |
LukevdBurg | 27:2b989633a518 | 35 | |
LukevdBurg | 27:2b989633a518 | 36 | char TestCase = 'A'; |
neilt6 | 0:8f2b6eed2a9d | 37 | |
neilt6 | 0:8f2b6eed2a9d | 38 | int main() |
neilt6 | 0:8f2b6eed2a9d | 39 | { |
LukevdBurg | 27:2b989633a518 | 40 | pc.baud(115200); |
neilt6 | 12:bd8b17cd6a7b | 41 | //Configure CRC, large frames, and write validation |
neilt6 | 10:ae649a596123 | 42 | sd.crc(true); |
neilt6 | 7:17ca3091939f | 43 | sd.large_frames(true); |
neilt6 | 12:bd8b17cd6a7b | 44 | sd.write_validation(true); |
neilt6 | 7:17ca3091939f | 45 | |
deldering95 | 26:dcced86ba984 | 46 | pc.format(8, SerialBase::None, 1); |
LukevdBurg | 27:2b989633a518 | 47 | |
LukevdBurg | 27:2b989633a518 | 48 | switch(TestCase){ |
LukevdBurg | 27:2b989633a518 | 49 | case 'A': |
LukevdBurg | 27:2b989633a518 | 50 | pc.printf("Programming succesfull\n"); |
LukevdBurg | 27:2b989633a518 | 51 | TestCase = 'B'; |
LukevdBurg | 27:2b989633a518 | 52 | wait(0.2); |
LukevdBurg | 27:2b989633a518 | 53 | case 'B': |
LukevdBurg | 27:2b989633a518 | 54 | pc.printf("\nTesting Serial communication.....\n"); |
LukevdBurg | 27:2b989633a518 | 55 | wait(0.2); |
LukevdBurg | 27:2b989633a518 | 56 | pc.printf("\tTransmit to PC Succesfull\n"); |
LukevdBurg | 27:2b989633a518 | 57 | TestCase = 'C'; |
LukevdBurg | 27:2b989633a518 | 58 | case 'C': |
LukevdBurg | 27:2b989633a518 | 59 | pc.printf("\nTesting Touch-Pad connections...\n"); |
LukevdBurg | 27:2b989633a518 | 60 | wait(0.2); |
LukevdBurg | 27:2b989633a518 | 61 | |
LukevdBurg | 27:2b989633a518 | 62 | TestCase = 'D'; |
LukevdBurg | 27:2b989633a518 | 63 | case 'D': |
LukevdBurg | 27:2b989633a518 | 64 | pc.printf("\nTesting LDR connectivity\n"); |
LukevdBurg | 27:2b989633a518 | 65 | for(int j; j < 5; j++){ |
LukevdBurg | 27:2b989633a518 | 66 | meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) |
LukevdBurg | 27:2b989633a518 | 67 | meas = meas * 3300; // Change the value to be in the 0 to 3300 range |
LukevdBurg | 27:2b989633a518 | 68 | pc.printf("\tMeasurement = %.0f mV\n", meas); |
LukevdBurg | 27:2b989633a518 | 69 | wait(0.2); |
LukevdBurg | 27:2b989633a518 | 70 | } |
LukevdBurg | 27:2b989633a518 | 71 | TestCase = 'E'; |
LukevdBurg | 27:2b989633a518 | 72 | case 'E': |
LukevdBurg | 27:2b989633a518 | 73 | pc.printf("\nTesting Protocol Led...\n"); |
LukevdBurg | 27:2b989633a518 | 74 | wait(0.2); |
LukevdBurg | 27:2b989633a518 | 75 | pc.printf("\tLeds blinking 10 times\n"); |
LukevdBurg | 27:2b989633a518 | 76 | for(int z; z < 10; z++){ |
LukevdBurg | 27:2b989633a518 | 77 | Led0 = 1; |
LukevdBurg | 27:2b989633a518 | 78 | Led1 = 1; |
LukevdBurg | 27:2b989633a518 | 79 | Led2 = 1; |
LukevdBurg | 27:2b989633a518 | 80 | Led3 = 1; |
LukevdBurg | 27:2b989633a518 | 81 | Led4 = 1; |
LukevdBurg | 27:2b989633a518 | 82 | wait(0.2); |
LukevdBurg | 27:2b989633a518 | 83 | Led0 = 0; |
LukevdBurg | 27:2b989633a518 | 84 | Led1 = 0; |
LukevdBurg | 27:2b989633a518 | 85 | Led2 = 0; |
LukevdBurg | 27:2b989633a518 | 86 | Led3 = 0; |
LukevdBurg | 27:2b989633a518 | 87 | Led4 = 0; |
LukevdBurg | 27:2b989633a518 | 88 | wait(0.2); |
LukevdBurg | 27:2b989633a518 | 89 | } |
LukevdBurg | 27:2b989633a518 | 90 | TestCase = 'F'; |
LukevdBurg | 27:2b989633a518 | 91 | case 'F': |
LukevdBurg | 27:2b989633a518 | 92 | pc.printf("\nTesting Led Ring...\n"); |
LukevdBurg | 27:2b989633a518 | 93 | TestCase = 'G'; |
LukevdBurg | 27:2b989633a518 | 94 | case 'G': |
LukevdBurg | 27:2b989633a518 | 95 | pc.printf("\nTesting SD-Card slot...\n"); |
LukevdBurg | 27:2b989633a518 | 96 | //Make sure a card is present |
LukevdBurg | 27:2b989633a518 | 97 | if (!sd.card_present()) { |
LukevdBurg | 27:2b989633a518 | 98 | pc.printf("\nNo card present!\n"); |
LukevdBurg | 27:2b989633a518 | 99 | } |
LukevdBurg | 27:2b989633a518 | 100 | |
LukevdBurg | 27:2b989633a518 | 101 | //Try to mount the SD card |
LukevdBurg | 27:2b989633a518 | 102 | pc.printf("\nMounting SD card..."); |
LukevdBurg | 27:2b989633a518 | 103 | if (sd.mount() != 0) { |
LukevdBurg | 27:2b989633a518 | 104 | pc.printf("failed!\n"); |
LukevdBurg | 27:2b989633a518 | 105 | } |
LukevdBurg | 27:2b989633a518 | 106 | pc.printf("success!\n"); |
neilt6 | 10:ae649a596123 | 107 | |
LukevdBurg | 27:2b989633a518 | 108 | //Display the card type |
LukevdBurg | 27:2b989633a518 | 109 | pc.printf("\tCard type: "); |
LukevdBurg | 27:2b989633a518 | 110 | SDFileSystem::CardType cardType = sd.card_type(); |
LukevdBurg | 27:2b989633a518 | 111 | if (cardType == SDFileSystem::CARD_NONE) |
LukevdBurg | 27:2b989633a518 | 112 | pc.printf("None\n"); |
LukevdBurg | 27:2b989633a518 | 113 | else if (cardType == SDFileSystem::CARD_MMC) |
LukevdBurg | 27:2b989633a518 | 114 | pc.printf("MMC\n"); |
LukevdBurg | 27:2b989633a518 | 115 | else if (cardType == SDFileSystem::CARD_SD) |
LukevdBurg | 27:2b989633a518 | 116 | pc.printf("SD\n"); |
LukevdBurg | 27:2b989633a518 | 117 | else if (cardType == SDFileSystem::CARD_SDHC) |
LukevdBurg | 27:2b989633a518 | 118 | pc.printf("SDHC\n"); |
LukevdBurg | 27:2b989633a518 | 119 | else |
LukevdBurg | 27:2b989633a518 | 120 | pc.printf("Unknown\n"); |
neilt6 | 17:e5b7469082c8 | 121 | |
LukevdBurg | 27:2b989633a518 | 122 | //Display the card capacity |
LukevdBurg | 27:2b989633a518 | 123 | pc.printf("\tSectors: %u\n", sd.disk_sectors()); |
LukevdBurg | 27:2b989633a518 | 124 | pc.printf("\tCapacity: %.1fMB\n", sd.disk_sectors() / 2048.0); |
neilt6 | 0:8f2b6eed2a9d | 125 | |
LukevdBurg | 27:2b989633a518 | 126 | //Unmount the SD card |
LukevdBurg | 27:2b989633a518 | 127 | sd.unmount(); |
LukevdBurg | 27:2b989633a518 | 128 | TestCase = 'H'; |
LukevdBurg | 27:2b989633a518 | 129 | case 'H': |
LukevdBurg | 27:2b989633a518 | 130 | pc.printf("\nTesting RTC...\n"); |
LukevdBurg | 27:2b989633a518 | 131 | pc.printf("Setting Time...\n"); |
LukevdBurg | 27:2b989633a518 | 132 | rtn_val = rtc.set_time(Time); |
LukevdBurg | 27:2b989633a518 | 133 | if (rtn_val == 0){ |
LukevdBurg | 27:2b989633a518 | 134 | pc.printf("\tDone\n"); |
LukevdBurg | 27:2b989633a518 | 135 | pc.printf("Repeating for 5 Seconds\n"); |
LukevdBurg | 27:2b989633a518 | 136 | } |
LukevdBurg | 27:2b989633a518 | 137 | else{ |
LukevdBurg | 27:2b989633a518 | 138 | pc.printf("Setting Time Failed"); |
LukevdBurg | 27:2b989633a518 | 139 | } |
LukevdBurg | 27:2b989633a518 | 140 | rtn_val = rtc.get_time(&Time); |
LukevdBurg | 27:2b989633a518 | 141 | pc.printf("\tTime = %u\n", Time); |
LukevdBurg | 27:2b989633a518 | 142 | wait(1); |
LukevdBurg | 27:2b989633a518 | 143 | rtn_val = rtc.get_time(&Time); |
LukevdBurg | 27:2b989633a518 | 144 | pc.printf("\tTime = %u\n", Time); |
LukevdBurg | 27:2b989633a518 | 145 | wait(1); |
LukevdBurg | 27:2b989633a518 | 146 | rtn_val = rtc.get_time(&Time); |
LukevdBurg | 27:2b989633a518 | 147 | pc.printf("\tTime = %u\n", Time); |
LukevdBurg | 27:2b989633a518 | 148 | wait(1); |
LukevdBurg | 27:2b989633a518 | 149 | rtn_val = rtc.get_time(&Time); |
LukevdBurg | 27:2b989633a518 | 150 | pc.printf("\tTime = %u\n", Time); |
LukevdBurg | 27:2b989633a518 | 151 | wait(1); |
LukevdBurg | 27:2b989633a518 | 152 | rtn_val = rtc.get_time(&Time); |
LukevdBurg | 27:2b989633a518 | 153 | pc.printf("\tTime = %u\n", Time); |
LukevdBurg | 27:2b989633a518 | 154 | wait(1); |
LukevdBurg | 27:2b989633a518 | 155 | |
LukevdBurg | 27:2b989633a518 | 156 | pc.printf("RTC Test Succesfull\n"); |
LukevdBurg | 27:2b989633a518 | 157 | break; |
LukevdBurg | 27:2b989633a518 | 158 | default: |
LukevdBurg | 27:2b989633a518 | 159 | pc.printf("Error while testing...\n"); |
LukevdBurg | 27:2b989633a518 | 160 | } |
LukevdBurg | 27:2b989633a518 | 161 | |
LukevdBurg | 27:2b989633a518 | 162 | pc.printf("\nAll test executed...\n"); |
LukevdBurg | 27:2b989633a518 | 163 | |
LukevdBurg | 27:2b989633a518 | 164 | ws.useII(WS2812::GLOBAL); // use per-pixel intensity scaling |
LukevdBurg | 27:2b989633a518 | 165 | |
LukevdBurg | 27:2b989633a518 | 166 | //// set up the colours we want to draw with |
LukevdBurg | 27:2b989633a518 | 167 | int colorbuf[NUM_COLORS] = {0xff0000,0x0000ff,0xffa500,0x555555,0x800080,0x000000}; //r b y w p off |
LukevdBurg | 27:2b989633a518 | 168 | r = 0; |
LukevdBurg | 27:2b989633a518 | 169 | g = 1; |
LukevdBurg | 27:2b989633a518 | 170 | b = 2; |
LukevdBurg | 27:2b989633a518 | 171 | y = 3; |
LukevdBurg | 27:2b989633a518 | 172 | w = 4; |
LukevdBurg | 27:2b989633a518 | 173 | // // for each of the colours (j) write out 10 of them |
LukevdBurg | 27:2b989633a518 | 174 | // // the pixels are written at the colour*10, plus the colour position |
LukevdBurg | 27:2b989633a518 | 175 | // // all modulus 60 so it wraps around |
LukevdBurg | 27:2b989633a518 | 176 | ws.setII(60); |
LukevdBurg | 27:2b989633a518 | 177 | // // Now the buffer is written, rotate it |
LukevdBurg | 27:2b989633a518 | 178 | // // by writing it out with an increasing offset |
LukevdBurg | 27:2b989633a518 | 179 | while (1) { |
LukevdBurg | 27:2b989633a518 | 180 | ws.setII(90); //intensity level (max = 255) |
LukevdBurg | 27:2b989633a518 | 181 | for(int j=0; j<6; j++) { |
LukevdBurg | 27:2b989633a518 | 182 | px.SetAll(colorbuf[j%7]); |
LukevdBurg | 27:2b989633a518 | 183 | for(int k = 1; k<32; k = k+2) { |
LukevdBurg | 27:2b989633a518 | 184 | px.Set(k, colorbuf[6]); |
LukevdBurg | 27:2b989633a518 | 185 | } |
LukevdBurg | 27:2b989633a518 | 186 | ws.write_offsets(px.getBuf(),0,0,0); |
LukevdBurg | 27:2b989633a518 | 187 | wait(3); |
neilt6 | 19:ae979143c796 | 188 | } |
neilt6 | 19:ae979143c796 | 189 | |
LukevdBurg | 27:2b989633a518 | 190 | ws.setII(25); |
LukevdBurg | 27:2b989633a518 | 191 | for(int j=0; j<6; j++) { |
LukevdBurg | 27:2b989633a518 | 192 | px.SetAll(colorbuf[j%7]); |
LukevdBurg | 27:2b989633a518 | 193 | ws.write_offsets(px.getBuf(),0,0,0); |
LukevdBurg | 27:2b989633a518 | 194 | wait(3); |
neilt6 | 19:ae979143c796 | 195 | } |
LukevdBurg | 27:2b989633a518 | 196 | |
LukevdBurg | 27:2b989633a518 | 197 | ws.setII(60); |
LukevdBurg | 27:2b989633a518 | 198 | for(int j=0; j<6; j++) { |
LukevdBurg | 27:2b989633a518 | 199 | px.SetAll(colorbuf[j%7]); |
LukevdBurg | 27:2b989633a518 | 200 | ws.write_offsets(px.getBuf(),0,0,0); |
LukevdBurg | 27:2b989633a518 | 201 | wait(3); |
LukevdBurg | 27:2b989633a518 | 202 | } |
LukevdBurg | 27:2b989633a518 | 203 | |
neilt6 | 19:ae979143c796 | 204 | |
LukevdBurg | 27:2b989633a518 | 205 | ws.setII(180); |
LukevdBurg | 27:2b989633a518 | 206 | for(int j=0; j<6; j++) { |
LukevdBurg | 27:2b989633a518 | 207 | px.SetAll(colorbuf[j%7]); |
LukevdBurg | 27:2b989633a518 | 208 | ws.write_offsets(px.getBuf(),0,0,0); |
LukevdBurg | 27:2b989633a518 | 209 | wait(3); |
LukevdBurg | 27:2b989633a518 | 210 | } |
LukevdBurg | 27:2b989633a518 | 211 | |
neilt6 | 17:e5b7469082c8 | 212 | |
LukevdBurg | 27:2b989633a518 | 213 | ws.setII(60); |
LukevdBurg | 27:2b989633a518 | 214 | for(int j=0; j<6; j++) { |
LukevdBurg | 27:2b989633a518 | 215 | px.SetAll(colorbuf[j%7]); |
LukevdBurg | 27:2b989633a518 | 216 | for(int k = 10; k<32; k++) { |
LukevdBurg | 27:2b989633a518 | 217 | px.Set(k, colorbuf[6]); |
LukevdBurg | 27:2b989633a518 | 218 | } |
LukevdBurg | 27:2b989633a518 | 219 | ws.write_offsets(px.getBuf(),0,0,0); |
LukevdBurg | 27:2b989633a518 | 220 | wait(3); |
neilt6 | 17:e5b7469082c8 | 221 | } |
LukevdBurg | 27:2b989633a518 | 222 | wait(5); |
neilt6 | 0:8f2b6eed2a9d | 223 | } |
neilt6 | 0:8f2b6eed2a9d | 224 | } |