Afficher Hello

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
vermaelen
Date:
Mon Mar 28 10:11:31 2022 +0000
Parent:
0:bd34a367f642
Commit message:
v1;

Changed in this revision

lib_matrix.h 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
diff -r bd34a367f642 -r 61f61158c345 lib_matrix.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib_matrix.h	Mon Mar 28 10:11:31 2022 +0000
@@ -0,0 +1,25 @@
+const unsigned char led_H[]= {
+    0xFF,0x18,0x18,0x18,0x18,0x18,0x18,0xFF
+};  //H
+const unsigned char led_E[]= {
+    0xFF,0xFF,0x99,0x99,0x99,0x99,0x99,0x99
+};  //E
+const unsigned char led_L[]= {
+    0xFF,0xFF,0xC0,0xC0,0xC0,0xC0,0xC0,0xC0
+};  //L
+const unsigned char led_O[]= {
+    0x7E,0x81,0x81,0x81,0x81,0x81,0x81,0x7E
+};  //O
+const unsigned char led_W[]= {
+    0x1F,0x60,0x80,0x40,0x40,0x80,0x60,0x1F
+};  //W
+const unsigned char led_blank[]= {
+    0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
+};  //blank
+const unsigned char led_heart[]= {
+    0x18,0x7E,0x7E,0xF8,0xF8,0x7E,0x7E,0x18
+};  //heart
+
+void disp(char c);
+void SPI_Write2(unsigned char MSB, unsigned char LSB);
+void Init_MAX7219(void);
diff -r bd34a367f642 -r 61f61158c345 main.cpp
--- a/main.cpp	Tue Nov 24 06:41:43 2015 +0000
+++ b/main.cpp	Mon Mar 28 10:11:31 2022 +0000
@@ -6,17 +6,62 @@
  */
 
 #include "mbed.h"
+#include "lib_matrix.h"
 
-SPI spi(PTD2, PTD3, PTD1);          // Arduino compatible MOSI, MISO, SCLK
-DigitalOut cs(PTD0);                // Chip select
+SPI spi(D11,D12,D13);          // Arduino compatible MOSI, MISO, SCLK
+DigitalOut cs(D14);                // Chip select
+
+int main()
+{
+    cs = 1;                         // CS initially High
+    spi.format(8,0);                // 8-bit format, mode 0,0
+    spi.frequency(1000000);         // SCLK = 1 MHz
+    Init_MAX7219();                 // Initialize the LED controller
+    char tab[20]="HELLOWO&&&";
+    int i=0;
+    while (1) {
+        disp(tab[i]);
+        i=(i+1)%10;
+        wait(0.5);
+        disp(' ');
+        wait(0.1);        // 1 sec delay
+
+    }
+}
 
-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
-
+void disp(char c)
+{
+    switch(c) {
+        case 'E' :
+            for(int i=1; i<9; i++)      // Write first character (8 rows)
+                SPI_Write2(i,led_E[i-1]);
+            break;
+        case 'H' :
+            for(int i=1; i<9; i++)      // Write first character (8 rows)
+                SPI_Write2(i,led_H[i-1]);
+            break;
+        case 'L' :
+            for(int i=1; i<9; i++)      // Write first character (8 rows)
+                SPI_Write2(i,led_L[i-1]);
+            break;
+        case 'O' :
+            for(int i=1; i<9; i++)      // Write first character (8 rows)
+                SPI_Write2(i,led_O[i-1]);
+            break;
+        case 'W' :                   // 1 sec delay
+            for(int i=1; i<9; i++)      // Write second character
+                SPI_Write2(i,led_W[i-1]);
+            break;
+        case ' ' :                   // 1 sec delay
+            for(int i=1; i<9; i++)      // Write second character
+                SPI_Write2(i,led_blank[i-1]);
+            break;
+        case '&' :                   // 1 sec delay
+            for(int i=1; i<9; i++)      // Write second character
+                SPI_Write2(i,led_heart[i-1]);
+            break;
+    }
+}
 /// Send two bytes to SPI bus
 void SPI_Write2(unsigned char MSB, unsigned char LSB)
 {
@@ -46,25 +91,3 @@
     SPI_Write2(0x0F, 0x00);         // Disable display test
     wait_ms(500);                   // 500 ms delay
 }
-
-int main()
-{
-    cs = 1;                         // CS initially High
-    spi.format(8,0);                // 8-bit format, mode 0,0
-    spi.frequency(1000000);         // SCLK = 1 MHz
-    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]);
-        wait(1);                    // 1 sec delay
-        for(int i=1; i<9; i++)      // Write second character
-            SPI_Write2(i,led2[i-1]);
-        wait(1);                    // 1 sec delay
-    }
-}
-
-
-
-
-
-