pls work

Dependencies:   mbed WS2813 PixelArray SDFileSystem ds3231

Fork of SDFileSystem_HelloWorld by Neil Thiessen

Files at this revision

API Documentation at this revision

Comitter:
LukevdBurg
Date:
Tue Jan 15 13:05:29 2019 +0000
Parent:
26:dcced86ba984
Commit message:
Test Code cu

Changed in this revision

PixelArray.lib Show annotated file Show diff for this revision Revisions of this file
WS2812.lib Show annotated file Show diff for this revision Revisions of this file
ds3231.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/PixelArray.lib	Tue Jan 15 13:05:29 2019 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/chris/code/PixelArray/#b45a70faaa83
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WS2812.lib	Tue Jan 15 13:05:29 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Momo-Medical/code/WS2813/#77c3528359b0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ds3231.lib	Tue Jan 15 13:05:29 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Maxim-Integrated/code/ds3231/#11630748e2f2
--- a/main.cpp	Thu Aug 02 14:42:56 2018 +0000
+++ b/main.cpp	Tue Jan 15 13:05:29 2019 +0000
@@ -1,137 +1,224 @@
 #include "mbed.h"
+#include "WS2812.h"
+#include "PixelArray.h"
 #include "SDFileSystem.h"
+#include <ds3231.h>
 
-Timer timer;
-//DigitalIn button(p21, PullUp);
+#define WS2812_BUF 32
+#define NUM_COLORS 7
+#define NUM_LEDS_PER_COLOR 32
+
+PixelArray px(WS2812_BUF);
+WS2812 ws(PB_9, WS2812_BUF, 10, 36, 20, 36);
+
+Ds3231 rtc(PB_7, PB_8);
+
 SDFileSystem sd(PC_12,PC_11,PC_10,PA_15, "sd", NC, SDFileSystem::SWITCH_NONE, 400000);
 RawSerial pc(PA_9,PA_10);
-char buffer[4096];
+
+int i = 0;
+int r,g,b,y,w;
+
+AnalogIn analog_value(PC_0);
+float meas;
 
-void writeTest()
-{
-    //Test write performance by creating a 1MB file
-    pc.printf("Testing %iB write performance...", sizeof(buffer));
-    FileHandle* file = sd.open("Test_File.bin", O_WRONLY | O_CREAT);
-    pc.printf("whatever u want\n");
-    if (file != NULL) {
-        timer.start();
-        for (int i = 0; i < (1048576 / sizeof(buffer)); i++) {
-            pc.printf("%d\n",i);
-            if (file->write(buffer, sizeof(buffer)) != sizeof(buffer)) {
-                timer.stop();
-                pc.printf("write error!\n");
-                timer.reset();
-                return;
-            }
-        }
-        timer.stop();
-        if (file->close())
-            pc.printf("failed to close file!\n");
-        else
-            pc.printf("done!\n\tResult: %.2fKB/s\n", 1024 / (timer.read_us() / 1000000.0));
-        timer.reset();
-    } else {
-        pc.printf("failed to create file!\n");
-    }
-}
+DigitalOut Led0 (PA_4);
+DigitalOut Led1 (PA_5);
+DigitalOut Led2 (PA_6);
+DigitalOut Led3 (PA_7);
+DigitalOut Led4 (PC_4);
 
-void readTest()
-{
-    //Test read performance by reading the 1MB file created by writeTest()
-    pc.printf("Testing %iB read performance...", sizeof(buffer));
-    FileHandle* file = sd.open("Test File.bin", O_RDONLY);
-    if (file != NULL) {
-        timer.start();
-        int iterations = 0;
-        while (file->read(buffer, sizeof(buffer)) == sizeof(buffer)){
-            iterations++;
-            pc.printf("%d\n",iterations);}
-        timer.stop();
-        if (iterations != (1048576 / sizeof(buffer)))
-            pc.printf("read error!\n");
-        else if (file->close())
-            pc.printf("failed to close file!\n");
-        else if (sd.remove("Test File.bin"))
-            pc.printf("failed to delete file!\n");
-        else
-            pc.printf("done!\n\tResult: %.2fKB/s\n", 1024 / (timer.read_us() / 1000000.0));
-        timer.reset();
-    } else {
-        pc.printf("failed to open file!\n");
-    }
-}
+ds3231_time_t Time = {12, 0, 0, 1, 0}; 
+uint16_t rtn_val;
+uint32_t SetTime;
+uint32_t GetTime;
+
+char TestCase = 'A';
 
 int main()
 {
+    pc.baud(115200);
     //Configure CRC, large frames, and write validation
     sd.crc(true);
     sd.large_frames(true);
     sd.write_validation(true);
 
-    pc.baud(115200);
     pc.format(8, SerialBase::None, 1);
-    pc.printf("pls work");
-    //Fill the buffer with random data for the write test
-    //srand(time(NULL));
-    for (int i = 0; i < sizeof(buffer); i++){
-        buffer[i] = rand();
-        pc.printf("pls work %d\n",i);}
+    
+    switch(TestCase){
+        case 'A':
+            pc.printf("Programming succesfull\n");
+            TestCase = 'B';
+            wait(0.2);
+        case 'B':
+            pc.printf("\nTesting Serial communication.....\n");
+            wait(0.2);
+            pc.printf("\tTransmit to PC Succesfull\n");
+            TestCase = 'C';
+        case 'C':
+            pc.printf("\nTesting Touch-Pad connections...\n");
+            wait(0.2);
+            
+            TestCase = 'D';
+        case 'D':
+            pc.printf("\nTesting LDR connectivity\n");
+            for(int j; j < 5; j++){
+                meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
+                meas = meas * 3300; // Change the value to be in the 0 to 3300 range
+                pc.printf("\tMeasurement = %.0f mV\n", meas);
+                wait(0.2);
+            }
+            TestCase = 'E';
+        case 'E':
+            pc.printf("\nTesting Protocol Led...\n");
+            wait(0.2);
+            pc.printf("\tLeds blinking 10 times\n");
+            for(int z; z < 10; z++){
+                Led0 = 1;
+                Led1 = 1;
+                Led2 = 1;
+                Led3 = 1;
+                Led4 = 1;
+                wait(0.2);
+                Led0 = 0;
+                Led1 = 0;
+                Led2 = 0;
+                Led3 = 0;
+                Led4 = 0;
+                wait(0.2);
+            }
+            TestCase = 'F';
+        case 'F':
+            pc.printf("\nTesting Led Ring...\n");   
+            TestCase = 'G';
+        case 'G':
+            pc.printf("\nTesting SD-Card slot...\n");
+            //Make sure a card is present
+            if (!sd.card_present()) {
+                pc.printf("\nNo card present!\n");
+            }
+
+            //Try to mount the SD card
+            pc.printf("\nMounting SD card...");
+            if (sd.mount() != 0) {
+                pc.printf("failed!\n");
+            }
+            pc.printf("success!\n");
 
-    while(1) {
-        //Simple button debouncing
-        wait(0.5);
+            //Display the card type
+            pc.printf("\tCard type: ");
+            SDFileSystem::CardType cardType = sd.card_type();
+            if (cardType == SDFileSystem::CARD_NONE)
+                pc.printf("None\n");
+            else if (cardType == SDFileSystem::CARD_MMC)
+                pc.printf("MMC\n");
+            else if (cardType == SDFileSystem::CARD_SD)
+                pc.printf("SD\n");
+            else if (cardType == SDFileSystem::CARD_SDHC)
+                pc.printf("SDHC\n");
+            else
+                pc.printf("Unknown\n");
 
-        //Print the start message
-        pc.printf("\nPress the button to perform tests: ");
+            //Display the card capacity
+            pc.printf("\tSectors: %u\n", sd.disk_sectors());
+            pc.printf("\tCapacity: %.1fMB\n", sd.disk_sectors() / 2048.0);
 
-        //Wait for the button to be pressed
-        //while(button);
-
-        //Make sure a card is present
-        if (!sd.card_present()) {
-            pc.printf("\nNo card present!\n");
-            continue;
+            //Unmount the SD card
+            sd.unmount();
+            TestCase = 'H';
+        case 'H':
+            pc.printf("\nTesting RTC...\n");
+            pc.printf("Setting Time...\n");
+            rtn_val = rtc.set_time(Time);
+            if (rtn_val == 0){
+                pc.printf("\tDone\n");
+                pc.printf("Repeating for 5 Seconds\n");
+                }
+            else{
+                pc.printf("Setting Time Failed");
+            }
+            rtn_val = rtc.get_time(&Time);
+            pc.printf("\tTime = %u\n", Time);
+            wait(1);
+            rtn_val = rtc.get_time(&Time);
+            pc.printf("\tTime = %u\n", Time);
+            wait(1);
+            rtn_val = rtc.get_time(&Time);
+            pc.printf("\tTime = %u\n", Time);
+            wait(1);
+            rtn_val = rtc.get_time(&Time);
+            pc.printf("\tTime = %u\n", Time);
+            wait(1);
+            rtn_val = rtc.get_time(&Time);
+            pc.printf("\tTime = %u\n", Time);
+            wait(1);
+           
+            pc.printf("RTC Test Succesfull\n");
+            break;
+        default:
+            pc.printf("Error while testing...\n");
+        }
+    
+    pc.printf("\nAll test executed...\n");
+    
+    ws.useII(WS2812::GLOBAL); // use per-pixel intensity scaling
+    
+    //// set up the colours we want to draw with
+    int colorbuf[NUM_COLORS] = {0xff0000,0x0000ff,0xffa500,0x555555,0x800080,0x000000}; //r b y w p off
+    r = 0;
+    g = 1;
+    b = 2;
+    y = 3;
+    w = 4;
+//    // for each of the colours (j) write out 10 of them
+//    // the pixels are written at the colour*10, plus the colour position
+//    // all modulus 60 so it wraps around
+    ws.setII(60);
+//    // Now the buffer is written, rotate it
+//    // by writing it out with an increasing offset
+    while (1) {
+        ws.setII(90); //intensity level (max = 255)
+        for(int j=0; j<6; j++) {
+            px.SetAll(colorbuf[j%7]);
+            for(int k = 1; k<32; k = k+2) {
+                px.Set(k, colorbuf[6]);
+            }
+            ws.write_offsets(px.getBuf(),0,0,0);
+            wait(3);
         }
 
-        //Try to mount the SD card
-        pc.printf("\nMounting SD card...");
-        if (sd.mount() != 0) {
-            pc.printf("failed!\n");
-            continue;
+        ws.setII(25);
+        for(int j=0; j<6; j++) {
+            px.SetAll(colorbuf[j%7]);
+            ws.write_offsets(px.getBuf(),0,0,0);
+            wait(3);
         }
-        pc.printf("success!\n");
+
+        ws.setII(60);
+        for(int j=0; j<6; j++) {
+            px.SetAll(colorbuf[j%7]);
+            ws.write_offsets(px.getBuf(),0,0,0);
+            wait(3);
+        }
+
 
-        //Display the card type
-        pc.printf("\tCard type: ");
-        SDFileSystem::CardType cardType = sd.card_type();
-        if (cardType == SDFileSystem::CARD_NONE)
-            pc.printf("None\n");
-        else if (cardType == SDFileSystem::CARD_MMC)
-            pc.printf("MMC\n");
-        else if (cardType == SDFileSystem::CARD_SD)
-            pc.printf("SD\n");
-        else if (cardType == SDFileSystem::CARD_SDHC)
-            pc.printf("SDHC\n");
-        else
-            pc.printf("Unknown\n");
+        ws.setII(180);
+        for(int j=0; j<6; j++) {
+            px.SetAll(colorbuf[j%7]);
+            ws.write_offsets(px.getBuf(),0,0,0);
+            wait(3);
+        }
+
 
-        //Display the card capacity
-        pc.printf("\tSectors: %u\n", sd.disk_sectors());
-        pc.printf("\tCapacity: %.1fMB\n", sd.disk_sectors() / 2048.0);
-
-        /*//Format the card
-        pc.printf("Formatting SD card...");
-        if (sd.format() != 0) {
-            pc.printf("failed!\n");
-            continue;
+       ws.setII(60);
+        for(int j=0; j<6; j++) {
+            px.SetAll(colorbuf[j%7]);
+            for(int k = 10; k<32; k++) {
+                px.Set(k, colorbuf[6]);
+            }
+            ws.write_offsets(px.getBuf(),0,0,0);
+            wait(3);
         }
-        pc.printf("success!\n");*/
-
-        //Perform a read/write test
-        writeTest();
-        readTest();
-
-        //Unmount the SD card
-        sd.unmount();
+        wait(5);
     }
 }