This program will run for https://www.sparkfun.com/products/760 as well as https://www.sparkfun.com/products/759 products from sparkfun

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Neel
Date:
Sat Apr 20 20:05:35 2013 +0000
Commit message:
LED Matrix SPI controller from Sparkfun.com

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Apr 20 20:05:35 2013 +0000
@@ -0,0 +1,225 @@
+#include "mbed.h"
+
+void draw_pattern(int pattern);
+DigitalOut myled(LED1);
+SPI spi(p5, p6, p7); // mosi, miso, sclk
+DigitalOut cs(p14);
+SPI spi1(p11, p12, p13);
+DigitalOut cs1(p18);
+
+/*volatile uint8_t arrow_green_right[] = {
+    0, 0, 0, 1, 1, 1, 0, 0,    
+    0, 0, 0, 1, 1, 1, 0, 0, 
+    0, 0, 0, 1, 1, 1, 0, 0, 
+    0, 0, 0, 1, 1, 1, 0, 0,    
+    0, 0, 0, 1, 1, 1, 0, 0, 
+    0, 1, 0, 1, 1, 1, 0, 1, 
+    0, 0, 1, 1, 1, 1, 1, 0, 
+    0, 0, 0, 1, 1, 1, 0, 0, 
+};*/
+
+volatile uint8_t arrow_red_left[] = {
+    0, 0, 0, 224, 224, 224, 0, 0,    
+    0, 0, 224, 224, 224, 224, 224, 0, 
+    0, 224, 0, 224, 224, 224, 0, 224, 
+    0, 0, 0, 224, 224, 224, 0, 0,    
+    0, 0, 0, 224, 224, 224, 0, 0, 
+    0, 0, 0, 224, 224, 224, 0, 0, 
+    0, 0, 0, 224, 224, 224, 0, 0, 
+    0, 0, 0, 224, 224, 224, 0, 0, 
+};
+
+volatile uint8_t arrow_blue_left[] = {
+    0, 0, 0, 3, 3, 3, 0, 0,    
+    0, 0, 3, 3, 3, 3, 3, 0, 
+    0, 3, 0, 3, 3, 3, 0, 3, 
+    0, 0, 0, 3, 3, 3, 0, 0,    
+    0, 0, 0, 3, 3, 3, 0, 0, 
+    0, 0, 0, 3, 3, 3, 0, 0, 
+    0, 0, 0, 3, 3, 3, 0, 0, 
+    0, 0, 0, 3, 3, 3, 0, 0, 
+};
+
+volatile uint8_t arrow_white_left[] = {
+    0, 0, 0, 95, 95, 95, 0, 0,    
+    0, 0, 95, 95, 95, 95, 95, 0, 
+    0, 95, 0, 95, 95, 95, 0, 95, 
+    0, 0, 0, 95, 95, 95, 0, 0,    
+    0, 0, 0, 95, 95, 95, 0, 0, 
+    0, 0, 0, 95, 95, 95, 0, 0, 
+    0, 0, 0, 95, 95, 95, 0, 0, 
+    0, 0, 0, 95, 95, 95, 0, 0, 
+};
+
+volatile uint8_t arrow_white_up[] = {
+    0, 0, 0, 0, 0, 0, 0, 0,    
+    0, 0, 0, 0, 0, 95, 0, 0, 
+    0, 0, 0, 0, 0, 0, 95, 0, 
+    0, 95, 95, 95, 95, 95, 95, 95,    
+    0, 95, 95, 95, 95, 95, 95, 95, 
+    95, 95, 95, 95, 95, 95, 95, 95, 
+    0, 0, 0, 0, 0, 0, 95, 0, 
+    0, 0, 0, 0, 0, 95, 0, 0, 
+};
+
+volatile uint8_t arrow_blue_up[] = {
+    0, 0, 0, 0, 0, 0, 0, 0,    
+    0, 0, 0, 0, 0, 3, 0, 0, 
+    0, 0, 0, 0, 0, 0, 3, 0, 
+    0, 3, 3, 3, 3, 3, 3, 3,    
+    0, 3, 3, 3, 3, 3, 3, 3, 
+    3, 3, 3, 3, 3, 3, 3, 3, 
+    0, 0, 0, 0, 0, 0, 3, 0, 
+    0, 0, 0, 0, 0, 3, 0, 0, 
+};
+
+volatile uint8_t arrow_white_down[] = {
+     0, 0, 0, 0, 95, 0, 0, 0,   
+     0, 0, 0, 95, 0, 0, 0, 0,
+     0, 0, 95, 95, 95, 95, 95, 95,
+     95, 95, 95, 95, 95, 95, 95, 95,    
+     95, 0, 95, 95, 95, 95, 95, 95,
+     95, 0, 0, 95, 0, 0, 0, 0,
+     0, 0, 0, 0, 95, 0, 0, 0,
+     0, 0, 0, 0, 0, 0, 0, 0,
+};
+
+volatile uint8_t arrow_blue_down[] = {
+     0, 0, 0, 0, 3, 0, 0, 0,   
+     0, 0, 0, 3, 0, 0, 0, 0,
+     0, 0, 3, 3, 3, 3, 3, 3,
+     3, 3, 3, 3, 3, 3, 3, 3,    
+     3, 0, 3, 3, 3, 3, 3, 3,
+     3, 0, 0, 3, 0, 0, 0, 0,
+     0, 0, 0, 0, 3, 0, 0, 0,
+     0, 0, 0, 0, 0, 0, 0, 0,
+};
+int main() 
+{
+    // Setup the spi for 8 bit data, high steady state clock,
+    // second edge capture, with a 100kHz clock rate
+    spi.format(8,3);
+    spi.frequency(100000);
+    /*cs = 0;
+    wait(0.5);
+    spi.write(0x25);
+    spi.write(2);
+    wait(0.5);
+    cs=1;*/
+    spi1.format(8,3);
+    spi1.frequency(100000);
+    //draw_pattern(0);
+    //draw_pattern(1);
+    draw_pattern(2);
+    draw_pattern(3);
+}
+
+
+void draw_pattern(int pattern)
+{
+    switch(pattern)
+    {
+        case 0:
+        {
+            while(1)
+              {
+              cs = 0;
+              //cs1 = 0;
+              myled = 0;
+              wait_ms(0.5); 
+              for(int k = 0; k<65;k++ )
+              {
+                spi.write(arrow_blue_down[k+1]);
+                //spi1.write(arrow_blue_up[k+1]);
+              }
+              wait_ms(0.5);
+              cs = 1;
+              //cs1 = 1;
+              }
+              
+             /* {
+              cs = 0;
+              //cs1 = 0;
+              myled = 0;
+              wait_ms(0.5); 
+              for(int k = 0; k<65;k++ )
+              {
+                spi.write(arrow_blue_up[k+1]);
+                //spi1.write(arrow_blue_up[k+1]);
+              }
+              wait_ms(0.5);
+              cs = 1;
+              //cs1 = 1;
+              }*/
+              
+              
+        }
+        case 1:
+        {
+            int i=0;
+            do
+            {
+              cs = 0;
+              //cs1 = 0;
+              myled = 1;
+              wait_ms(0.5); 
+              for(int k=0;k<65;k++)
+              {
+                spi.write(arrow_red_left[k+1]);
+                //spi1.write(image[k+1]);
+              }
+              wait_ms(0.5);
+              cs = 1;
+              myled=0;
+              wait(1);
+              i++;
+            }while(i<10);
+            break;
+        }
+        case 2:
+        {
+            int i=0;
+            do
+            {
+              cs1 = 0;
+              //cs1 = 0;
+              myled = 1;
+              wait_ms(0.5); 
+              for(int k=0;k<65;k++)
+              {
+                spi1.write(arrow_white_up[k+1]);
+                //spi1.write(image[k+1]);
+              }
+              wait_ms(0.5);
+              cs1 = 1;
+              myled=0;
+              wait(1);
+              i++;
+            }while(i<10);
+            break;
+        }
+        
+        case 3:
+        {
+            int i=0;
+            do
+            {
+              cs = 0;
+              //cs1 = 0;
+              myled = 1;
+              wait_ms(0.5); 
+              for(int k=0;k<65;k++)
+              {
+                spi.write(arrow_white_down[k+1]);
+                //spi1.write(image[k+1]);
+              }
+              wait_ms(0.5);
+              cs = 1;
+              myled=0;
+              wait(1);
+              i++;
+            }while(i<10);
+            break;
+        }
+     }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Apr 20 20:05:35 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/3d0ef94e36ec
\ No newline at end of file