LPC1768 programm for the led matrix.

Dependencies:   BufferedSerial DS3231 mbed-rtos mbed

Revision:
1:3a39b1439456
Parent:
0:41f9c251097c
Child:
2:d5472e4a55bf
--- a/main.cpp	Fri Jul 15 07:13:49 2016 +0000
+++ b/main.cpp	Wed Aug 03 07:28:20 2016 +0000
@@ -6,92 +6,141 @@
 //------------------------------------------------------------------------------------------------------
 // Analog I/O, Digital I/O, etc.
 //------------------------------------------------------------------------------------------------------
-DigitalOut  ds1(p5), ds2(p10),  oe1(p6),  stcp1(p7),  shcp1(p8),  mr1(p9),  led(LED1);
-
+DigitalOut  ds1(p5), oe1(p6), stcp1(p7), shcp1(p8), mr1(p9);
+AnalogIn    ain(p20);
+Ticker      tick;
 /*
 DS    normal        Serial Data Output  Schreibt vor ob das LED 0 oder 1 ist.
 OE    invertiert    Output-Enable       Aktiviert oder deaktiviert die LEDs.
 SHCP  normal        Shift register clk  Setzt Position mit kurzen Impulsen fest.
 STCP  normal        Storage reg. clk    Setzt Reihe mit kurzen Impulsen fest.
 MR    invertiert    Master reset        resetet den Storage. Muss mit STCP angezeigt werden.
+
 */
-
-//  ,,,,,
-//  |xox|  
-//  |oxo|
-//  |xox|
-//  '''''
-
-
 //------------------------------------------------------------------------------------------------------
 // Voids & Ticker, Ints, etc.
 //------------------------------------------------------------------------------------------------------
-int a, b, x, y, z=0, t, temp;
+int a = 0, x, y, z, t, temp, speed=10;
 
-int const data[][8] = {   {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
-                          {0x03,0x03,0x03,0x03,0x03,0x03,0x03,0x03},
-                          {0x07,0x07,0x07,0x07,0x07,0x07,0x07,0x07},
-                          {0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f,0x0f},
-                          {0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f},
-                          {0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f},
-                          {0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f,0x7f},
-                          {0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff},
-                          {0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
-                          {0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc,0xfc},
-                          {0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8,0xf8},
-                          {0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0},
-                          {0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0,0xe0},
-                          {0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0},
-                          {0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80},
-                          {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}};
-
-int const size_y = sizeof(data)     /   sizeof(data[0]);
-int const size_x = sizeof(data[0])  /   sizeof(data[0][0]);
-
-bool row_temp[8][8]= {{},{},{},{},{},{},{},{}};
-void save_srg(), reset_srg();   //, set_srg(bool status_[]);
-//------------------------------------------------------------------------------------------------------
+int zahl[][8] ={
+{255,255,112,56,56,112,255,255},
+{255,112,56,56,112,255,255,0},
+{112,56,56,112,255,255,0,2},
+{56,56,112,255,255,0,2,23},
+{56,112,255,255,0,2,23,21},
+{112,255,255,0,2,23,21,21},
+{255,255,0,2,23,21,21,31},
+{255,0,2,23,21,21,31,15},
+{0,2,23,21,21,31,15,0},
+{2,23,21,21,31,15,0,17},
+{23,21,21,31,15,0,17,27},
+{21,21,31,15,0,17,27,14},
+{21,31,15,0,17,27,14,14},
+{31,15,0,17,27,14,14,27},
+{15,0,17,27,14,14,27,17},
+{0,17,27,14,14,27,17,0},
+{17,27,14,14,27,17,0,14},
+{27,14,14,27,17,0,14,31},
+{14,14,27,17,0,14,31,17},
+{14,27,17,0,14,31,17,17},
+{27,17,0,14,31,17,17,31},
+{17,0,14,31,17,17,31,14},
+{0,14,31,17,17,31,14,0},
+{14,31,17,17,31,14,0,31},
+{31,17,17,31,14,0,31,31},
+{17,17,31,14,0,31,31,24},
+{17,31,14,0,31,31,24,24},
+{31,14,0,31,31,24,24,31},
+{14,0,31,31,24,24,31,15},
+{0,31,31,24,24,31,15,0},
+{31,31,24,24,31,15,0,0},
+{31,24,24,31,15,0,0,0},
+{24,24,31,15,0,0,0,0},
+{24,31,15,0,0,0,0,0},
+{31,15,0,0,0,0,0,0},
+{15,0,0,0,0,0,0,0},
+{0,0,0,0,0,0,0,0},
+{0,0,0,0,0,0,0,255},
+{0,0,0,0,0,0,255,255},
+{0,0,0,0,0,255,255,112},
+{0,0,0,0,255,255,112,56},
+{0,0,0,255,255,112,56,56},
+{0,0,255,255,112,56,56,112},
+{0,255,255,112,56,56,112,255}
 
 
+};
+
+int const size_y = sizeof(zahl)     /   sizeof(zahl[0]);
+int const size_x = sizeof(zahl[0])  /   sizeof(zahl[0][0]);
+
+bool row_temp[8];
+void shift_srg(), reset_srg(), setSpeed();   //, set_srg(bool status_[]);
+//------------------------------------------------------------------------------------------------------
+// Vorgang
+//------------------------------------------------------------------------------------------------------
+/*
+Zuerst müssen die ersten 8 DS den Wert 1 entsprechen, weil diese für die Kathoden Seite der Matrix ist.
+Die beiden 74HC595-ICs sind miteinander über dem Q7s und DS verbunden. Was aus dem ersten IC herauskommt,
+wird beim zweiten als Eingangswert benützt.
+*/
 //------------------------------------------------------------------------------------------------------
 // Main
 //------------------------------------------------------------------------------------------------------
 int main()
 {
-    oe1=1;
+    mr1 = 1;
+    oe1 = 0;
+    ds1 = 0;
+    stcp1 = 0;
+    shcp1 = 0;
+    
+    tick.attach(&setSpeed,0.005);
     reset_srg();
-    oe1=0;
+    
+    
+    
     while(1)
-    {   
-        for(y = 0; y < size_y; y++)       // Frames
+    {
+        for(t = 0; t < speed; t++)
         {
-            for(t = 0; t < 80; t++)      // Zeit
+            for(z = 0; z < 8; z++)
             {
-                for(a = 0; a < size_x; a++)        // row_temp befüllen
+                
+                for(y = 0; y < 8; y++)
                 {
-                    temp=data[y][a];
-                    for(x = 0; x < size_x; x++)
+                    row_temp[y] = (zahl[a][z] >> y) & 1;
+                }
+                
+                for(x = 0; x < 8; x++)
+                {
+                    if(x == z)
                     {
-                        row_temp[a][x]=(temp >> x) & 1;
-                    }                    
-                }   // Ende for-a
-                for(z = 0; z < size_x; z++)
-                {
-                    for(a=0;a<8;a++)
+                        ds1 = 1;
+                    }
+                    else
                     {
-                        ds2 = 1;
-                        ds1 = row_temp[z][a];
-                        save_srg();
-                    }   // Ende for-a
-                    stcp1 = 1;
-                    stcp1 = 0;
-                    wait_ms(1);
-                    
-                    
-                }   // Ende for-z
-            }   // Ende for-t
-        }   // Ende for-y
-    }   // Ende while
+                        ds1 = 0;
+                    }
+                    shift_srg();
+                }
+                
+                for(x = 0; x < 8; x++)
+                {
+                    ds1 = row_temp[x];
+                    shift_srg();
+                }
+                
+                stcp1 = 1;
+                wait_ms(0.1);
+                stcp1 = 0;
+                
+            }
+        }
+        a++;
+        if(a == size_y)
+            a = 0;
+    }
 }   // Ende main
 
 
@@ -99,46 +148,39 @@
 // Voids & Floats
 //------------------------------------------------------------------------------------------------------
 
-void save_srg()
+void shift_srg()
 {
+    wait_ms(0.1);     // Perioden-Dauer 2ms, später verkürzen
     shcp1 = 1;
+    wait_ms(0.1);
     shcp1 = 0;
 }
 
-
 void reset_srg()
 {
     mr1 = 0;
-    save_srg();
-    stcp1 = 1;
-    stcp1 = 0;
-    
+    wait_ms(0.1);     // Reset-Puls 1ms, später verkürzen
     mr1 = 1;   
 }
 
+void setSpeed()
+{
+    speed = ain * 1000;
+}
+
 /*
-void set_srg(bool status_[])
-{
-    for(x=0;x<3;x++)
+for(x = 0; x < 16; x++)
     {
-        ds1 = status_bin[x];
-        save_srg();
-        wait(0.5);
-        stcp1 = 1;
-        stcp1 = 0;
-    }
+        switch(x)
+        {   // 0-7 = Kathode, 8-15 = Anoden
+        case 7: case 9: case 10: case 11: case 13: case 14: case 15:
+            ds1 = 1;
+            shift_srg();
+            break;
+        default:
+            ds1 = 0;
+            shift_srg();
+            break;
+        }    
+    }*/
     
-}*/
-
-
-/*for(i=0;i<100;i++)
-        {
-            for(y=0;y<8;y++)
-            {
-                if(i>=brightness[y])
-                    status_bin[y] = false;
-                else
-                    status_bin[y] = status_[y];
-            }
-            set_srg(status_bin);
-        }*/
\ No newline at end of file