LED via I2C 9555

Dependencies:   mbed

Revision:
1:d1a664b263dc
Parent:
0:951a35674581
diff -r 951a35674581 -r d1a664b263dc main.cpp
--- a/main.cpp	Tue Nov 18 14:17:57 2014 +0000
+++ b/main.cpp	Sun Jan 25 17:30:27 2015 +0000
@@ -1,76 +1,75 @@
-#include "mbed.h" // Softwarestand: 19.1.2014
+/***********************************
+name:   BERTL_2014_LAMPENTEST 
+modyfied by ENE@bulme.at
+description:
+  Alle LED sind INVERS dh 0 = EIN;  1 = AUS;
+***************************************/
+#include "mbed.h"               // Softwarestand: 19.1.2014
 /*** Portkonfiguration ***/
-Serial pc(USBTX, USBRX); // tx, rx
+Serial pc(USBTX, USBRX);        // tx, rx
 I2C i2c(p28,p27);
 
 /*** Funktionsdefinitionen ***/
-Ticker sekunden;
-Ticker blink;
-
-/*** Variablendefinitionen ***/
-// int x = 1 ;
-// int y = 0 ;
-// bool var1 = false;     
-
-const int addr = 0x40; // I2C-Adresse PCA9555
-char cmd[3];           // Datenarray für I2C
+const int addr = 0x40;          // I2C-Adresse des PCA9555
+char cmd[3];                    // Datenarray für I2C
 
 /*** Funktionen ***/
-
 int main()
 {
-/*** I2C Konfigurationen ***/
-        i2c.frequency(40000);  // I2C Frequenz 40kHz
-       
-        cmd[0] = 0x06;
-        cmd[1] = 0x00;
-        i2c.write(addr, cmd, 2); // Define Port0 = Out
+        /*** I2C Konfigurationen ***/
+        i2c.frequency(40000);    // I2C Frequenz 40kHz
+        cmd[0] = 0x06;           // Comman6 6 Portkonfiguration Port 0
+        cmd[1] = 0x00;           // 00-> Port 0 = OUTPUT (all Pins 00)
+        i2c.write(addr, cmd, 2); // Sende Adresse 0x40; cmd, s  -> 0x06 0x00
+                                 // Defines Port0 as Output
+        cmd[0] = 0x02;           // OUTPUT Port 0 
+        
 /*** Hauptprogramm - Endlosschleife ***/
     while(1) 
-    {
-        cmd[0] = 0x02;
-        cmd[1] = 0xFE;           // Alle LED ON  
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0x00
+    {                                               
+                                 //                   0x00      
+        cmd[1] = 0x00;           // Alle LED EIN      0000 0000
+        i2c.write(addr, cmd, 2); 
+        wait(2); 
+                                 //                 0xF    F 
+        cmd[1] = 0x00;           // Alle LED AUS      1111 1111
+        i2c.write(addr, cmd, 2); 
+        wait(0.5); 
+                                 //                   F    E
+        cmd[1] = 0xFE;           // D1 vorn links ws  1111 1110
+        i2c.write(addr, cmd, 2); 
+        wait(0.5);
+                                 //                    F    D          
+        cmd[1] = 0xFD;           // D2 vorn links ge   1111 1101
+        i2c.write(addr, cmd, 2); 
+        wait(0.5);
+                                 //                    F    B   
+        cmd[1] = 0xFB;           // D4 vorn rechts ws  1111 1011
+        i2c.write(addr, cmd, 2); 
         wait(0.5);
         
-        cmd[0] = 0x02;           //
-        cmd[1] = 0xFD;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
-        wait(0.5);
-      
-        cmd[0] = 0x02;           //
-        cmd[1] = 0xFB;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
+        cmd[1] = 0xF7;           // sieh ab hier in den Schaltplan 
+        i2c.write(addr, cmd, 2); 
         wait(0.5);
         
-        cmd[0] = 0x02;           //
-        cmd[1] = 0xF7;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
+        cmd[1] = 0xEF;           // 
+        i2c.write(addr, cmd, 2); 
         wait(0.5);
         
-        cmd[0] = 0x02;           //
-        cmd[1] = 0xEF;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
+        cmd[1] = 0xDF;           // 
+        i2c.write(addr, cmd, 2); 
         wait(0.5);
         
-        cmd[0] = 0x02;           //
-        cmd[1] = 0xDF;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
-        wait(0.5);
-        
-        cmd[0] = 0x02;           //
-        cmd[1] = 0xBF;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
+        cmd[1] = 0xBF;           
+        i2c.write(addr, cmd, 2); 
         wait(0.5);
         
-        cmd[0] = 0x02;           //
-        cmd[1] = 0x7F;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
+        cmd[1] = 0x7F;           
+        i2c.write(addr, cmd, 2); 
         wait(0.5);
-        
-        cmd[0] = 0x02;           //
-        cmd[1] = 0x00;           // Alle LED OFF
-        i2c.write(addr, cmd, 2); // Def. Port0 = 0xFF
-        wait(2);                                                                                              
+                                 //                   F    F   
+        cmd[1] = 0xFF;           // Alle LED AUS      1111 1111
+        i2c.write(addr, cmd, 2); 
+        wait(1);                                                                                   
     }
 }