Simple demo to drive a 8x8-as LED matrix by a MAX7219 LED driver IC. After initialisation two characters (H and W) are displayed alternatively. The MAX7219 IC is driven by hardware SPI: SPI0 module at PTD1, PTD2, PTD3.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Diego_Mbed
Date:
Mon May 18 16:23:09 2020 +0000
Parent:
0:bd34a367f642
Commit message:
Controlador con driver max7219

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Tue Nov 24 06:41:43 2015 +0000
+++ b/main.cpp	Mon May 18 16:23:09 2020 +0000
@@ -7,15 +7,39 @@
 
 #include "mbed.h"
 
-SPI spi(PTD2, PTD3, PTD1);          // Arduino compatible MOSI, MISO, SCLK
-DigitalOut cs(PTD0);                // Chip select
+SPI spi(D11, NC, D13);          // Arduino compatible MOSI, MISO, SCLK
+DigitalOut cs(D10);                // Chip select
 
-const unsigned char led1[]= {
-    0xFF,0x18,0x18,0x18,0x18,0x18,0x18,0xFF
-};  //H
-const unsigned char led2[]= {
-    0x1F,0x60,0x80,0x40,0x40,0x80,0x60,0x1F
-};  //W
+const unsigned char num1[]= {
+    0x00,0x00,0x00,0x42,0x7F,0x40,0x00,0x00
+};  //1
+const unsigned char num2[]= {
+    0x00,0x46,0x61,0x51,0x49,0x46,0x00,0x00
+};  //2
+const unsigned char num3[]= {
+    0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00
+};  //3
+const unsigned char num4[]= {
+    0x00,0x0C,0x0A,0x09,0x7F,0x08,0x00,0x00
+};  //4
+const unsigned char num5[]= {
+    0x00,0x00,0x4F,0x49,0x49,0x31,0x00,0x00
+};  //5
+const unsigned char num6[]= {
+    0x00,0x00,0x3C,0x4A,0x49,0x30,0x00,0x00
+};  //6
+const unsigned char num7[]= {
+    0x00,0x00,0x61,0x11,0x09,0x07,0x00,0x00
+};  //7
+const unsigned char num8[]= {
+    0x00,0x00,0x36,0x49,0x49,0x36,0x00,0x00
+};  //8
+const unsigned char num9[]= {
+    0x00,0x00,0x06,0x49,0x49,0x3E,0x00,0x00
+};  //9
+const unsigned char num0[]= {
+    0x00,0x00,0x3E,0x41,0x41,0x3E,0x00,0x00
+};  //0
 
 /// Send two bytes to SPI bus
 void SPI_Write2(unsigned char MSB, unsigned char LSB)
@@ -55,10 +79,34 @@
     Init_MAX7219();                 // Initialize the LED controller
     while (1) {
         for(int i=1; i<9; i++)      // Write first character (8 rows)
-            SPI_Write2(i,led1[i-1]);
+            SPI_Write2(i,num1[i-1]);
         wait(1);                    // 1 sec delay
         for(int i=1; i<9; i++)      // Write second character
-            SPI_Write2(i,led2[i-1]);
+            SPI_Write2(i,num2[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num3[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num4[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num5[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num6[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num7[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num8[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num9[i-1]);
+        wait(1);
+        for(int i=1; i<9; i++)      // Write second character
+            SPI_Write2(i,num0[i-1]);
         wait(1);                    // 1 sec delay
     }
 }