pls work
Dependencies: mbed WS2813 PixelArray SDFileSystem ds3231
Fork of SDFileSystem_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "WS2812.h" 00003 #include "PixelArray.h" 00004 #include "SDFileSystem.h" 00005 #include <ds3231.h> 00006 00007 #define WS2812_BUF 32 00008 #define NUM_COLORS 7 00009 #define NUM_LEDS_PER_COLOR 32 00010 00011 PixelArray px(WS2812_BUF); 00012 WS2812 ws(PB_9, WS2812_BUF, 10, 36, 20, 36); 00013 00014 Ds3231 rtc(PB_7, PB_8); 00015 00016 SDFileSystem sd(PC_12,PC_11,PC_10,PA_15, "sd", NC, SDFileSystem::SWITCH_NONE, 400000); 00017 RawSerial pc(PA_9,PA_10); 00018 00019 int i = 0; 00020 int r,g,b,y,w; 00021 00022 AnalogIn analog_value(PC_0); 00023 float meas; 00024 00025 DigitalOut Led0 (PA_4); 00026 DigitalOut Led1 (PA_5); 00027 DigitalOut Led2 (PA_6); 00028 DigitalOut Led3 (PA_7); 00029 DigitalOut Led4 (PC_4); 00030 00031 ds3231_time_t Time = {12, 0, 0, 1, 0}; 00032 uint16_t rtn_val; 00033 uint32_t SetTime; 00034 uint32_t GetTime; 00035 00036 char TestCase = 'A'; 00037 00038 int main() 00039 { 00040 pc.baud(115200); 00041 //Configure CRC, large frames, and write validation 00042 sd.crc(true); 00043 sd.large_frames(true); 00044 sd.write_validation(true); 00045 00046 pc.format(8, SerialBase::None, 1); 00047 00048 switch(TestCase){ 00049 case 'A': 00050 pc.printf("Programming succesfull\n"); 00051 TestCase = 'B'; 00052 wait(0.2); 00053 case 'B': 00054 pc.printf("\nTesting Serial communication.....\n"); 00055 wait(0.2); 00056 pc.printf("\tTransmit to PC Succesfull\n"); 00057 TestCase = 'C'; 00058 case 'C': 00059 pc.printf("\nTesting Touch-Pad connections...\n"); 00060 wait(0.2); 00061 00062 TestCase = 'D'; 00063 case 'D': 00064 pc.printf("\nTesting LDR connectivity\n"); 00065 for(int j; j < 5; j++){ 00066 meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0) 00067 meas = meas * 3300; // Change the value to be in the 0 to 3300 range 00068 pc.printf("\tMeasurement = %.0f mV\n", meas); 00069 wait(0.2); 00070 } 00071 TestCase = 'E'; 00072 case 'E': 00073 pc.printf("\nTesting Protocol Led...\n"); 00074 wait(0.2); 00075 pc.printf("\tLeds blinking 10 times\n"); 00076 for(int z; z < 10; z++){ 00077 Led0 = 1; 00078 Led1 = 1; 00079 Led2 = 1; 00080 Led3 = 1; 00081 Led4 = 1; 00082 wait(0.2); 00083 Led0 = 0; 00084 Led1 = 0; 00085 Led2 = 0; 00086 Led3 = 0; 00087 Led4 = 0; 00088 wait(0.2); 00089 } 00090 TestCase = 'F'; 00091 case 'F': 00092 pc.printf("\nTesting Led Ring...\n"); 00093 TestCase = 'G'; 00094 case 'G': 00095 pc.printf("\nTesting SD-Card slot...\n"); 00096 //Make sure a card is present 00097 if (!sd.card_present()) { 00098 pc.printf("\nNo card present!\n"); 00099 } 00100 00101 //Try to mount the SD card 00102 pc.printf("\nMounting SD card..."); 00103 if (sd.mount() != 0) { 00104 pc.printf("failed!\n"); 00105 } 00106 pc.printf("success!\n"); 00107 00108 //Display the card type 00109 pc.printf("\tCard type: "); 00110 SDFileSystem::CardType cardType = sd.card_type(); 00111 if (cardType == SDFileSystem::CARD_NONE) 00112 pc.printf("None\n"); 00113 else if (cardType == SDFileSystem::CARD_MMC) 00114 pc.printf("MMC\n"); 00115 else if (cardType == SDFileSystem::CARD_SD) 00116 pc.printf("SD\n"); 00117 else if (cardType == SDFileSystem::CARD_SDHC) 00118 pc.printf("SDHC\n"); 00119 else 00120 pc.printf("Unknown\n"); 00121 00122 //Display the card capacity 00123 pc.printf("\tSectors: %u\n", sd.disk_sectors()); 00124 pc.printf("\tCapacity: %.1fMB\n", sd.disk_sectors() / 2048.0); 00125 00126 //Unmount the SD card 00127 sd.unmount(); 00128 TestCase = 'H'; 00129 case 'H': 00130 pc.printf("\nTesting RTC...\n"); 00131 pc.printf("Setting Time...\n"); 00132 rtn_val = rtc.set_time(Time); 00133 if (rtn_val == 0){ 00134 pc.printf("\tDone\n"); 00135 pc.printf("Repeating for 5 Seconds\n"); 00136 } 00137 else{ 00138 pc.printf("Setting Time Failed"); 00139 } 00140 rtn_val = rtc.get_time(&Time); 00141 pc.printf("\tTime = %u\n", Time); 00142 wait(1); 00143 rtn_val = rtc.get_time(&Time); 00144 pc.printf("\tTime = %u\n", Time); 00145 wait(1); 00146 rtn_val = rtc.get_time(&Time); 00147 pc.printf("\tTime = %u\n", Time); 00148 wait(1); 00149 rtn_val = rtc.get_time(&Time); 00150 pc.printf("\tTime = %u\n", Time); 00151 wait(1); 00152 rtn_val = rtc.get_time(&Time); 00153 pc.printf("\tTime = %u\n", Time); 00154 wait(1); 00155 00156 pc.printf("RTC Test Succesfull\n"); 00157 break; 00158 default: 00159 pc.printf("Error while testing...\n"); 00160 } 00161 00162 pc.printf("\nAll test executed...\n"); 00163 00164 ws.useII(WS2812::GLOBAL); // use per-pixel intensity scaling 00165 00166 //// set up the colours we want to draw with 00167 int colorbuf[NUM_COLORS] = {0xff0000,0x0000ff,0xffa500,0x555555,0x800080,0x000000}; //r b y w p off 00168 r = 0; 00169 g = 1; 00170 b = 2; 00171 y = 3; 00172 w = 4; 00173 // // for each of the colours (j) write out 10 of them 00174 // // the pixels are written at the colour*10, plus the colour position 00175 // // all modulus 60 so it wraps around 00176 ws.setII(60); 00177 // // Now the buffer is written, rotate it 00178 // // by writing it out with an increasing offset 00179 while (1) { 00180 ws.setII(90); //intensity level (max = 255) 00181 for(int j=0; j<6; j++) { 00182 px.SetAll(colorbuf[j%7]); 00183 for(int k = 1; k<32; k = k+2) { 00184 px.Set(k, colorbuf[6]); 00185 } 00186 ws.write_offsets(px.getBuf(),0,0,0); 00187 wait(3); 00188 } 00189 00190 ws.setII(25); 00191 for(int j=0; j<6; j++) { 00192 px.SetAll(colorbuf[j%7]); 00193 ws.write_offsets(px.getBuf(),0,0,0); 00194 wait(3); 00195 } 00196 00197 ws.setII(60); 00198 for(int j=0; j<6; j++) { 00199 px.SetAll(colorbuf[j%7]); 00200 ws.write_offsets(px.getBuf(),0,0,0); 00201 wait(3); 00202 } 00203 00204 00205 ws.setII(180); 00206 for(int j=0; j<6; j++) { 00207 px.SetAll(colorbuf[j%7]); 00208 ws.write_offsets(px.getBuf(),0,0,0); 00209 wait(3); 00210 } 00211 00212 00213 ws.setII(60); 00214 for(int j=0; j<6; j++) { 00215 px.SetAll(colorbuf[j%7]); 00216 for(int k = 10; k<32; k++) { 00217 px.Set(k, colorbuf[6]); 00218 } 00219 ws.write_offsets(px.getBuf(),0,0,0); 00220 wait(3); 00221 } 00222 wait(5); 00223 } 00224 }
Generated on Wed Jul 20 2022 22:11:37 by 1.7.2