BERTL Taster, Forward, Reverse, I²C, Martin Winkler

Dependencies:   mbed

Revision:
0:b1af0438774e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jun 15 18:27:29 2015 +0000
@@ -0,0 +1,74 @@
+#include "mbed.h"
+
+I2C i2c(p28, p27);
+
+DigitalOut MotorL(P1_15);         
+DigitalOut MotorLf(P1_1);   
+DigitalOut MotorLr(P1_0);   
+ 
+DigitalOut MotorR(P0_21);
+DigitalOut MotorRf(P1_3);
+DigitalOut MotorRr(P1_4);
+
+DigitalOut Blau(P1_28);
+
+int taster = 0;
+
+int main() {
+    
+    Blau = 0;
+    MotorL = MotorR = 1;
+    MotorLf = 1;
+    MotorRf = 1;
+    
+    i2c.start();
+       i2c.write(0x40);   // Adresse des PCA9555 = 40 
+                          // das letzte Bit = 0 -> schreiben  0040 0000
+       i2c.write(0x06);   // Befehl für das IO Port 0 -> siehe SCHEMA des PCA9555
+       i2c.write(0x00);   // Schalte alle Pins des Ports als OUTPUT
+    i2c.stop();  
+    
+    i2c.start();
+                i2c.write(0x40);  // Adresse & schreiben
+                i2c.write(0x02);  // 
+                i2c.write(~5);  // schriebn auf Port 0 den INVERSEN Wert von btn
+            i2c.stop();
+    
+    while(1)
+    {
+        i2c.start();
+                i2c.write(0x40);
+                i2c.write(0x01);        
+       
+            i2c.start();
+                i2c.write(0x41); 
+                taster = i2c.read(0);
+            i2c.stop();
+            
+        if(taster == 1 || taster == 3 || taster == 5 || taster == 7 || taster == 9 || taster == 11 || taster == 13 || taster == 15)
+        {
+            MotorLf = MotorRf = 0;
+            MotorLr = MotorRr = 1;
+            i2c.start();
+                i2c.write(0x40);  // Adresse & schreiben
+                i2c.write(0x02);  // 
+                i2c.write(~80);  // schriebn auf Port 0 den INVERSEN Wert von btn
+            i2c.stop();
+        }
+        else if(taster == 2 || taster == 3 || taster == 6 || taster == 7 || taster == 10 || taster == 11 || taster == 14 || taster == 15)
+        {
+            i2c.start();
+                i2c.write(0x40);  // Adresse & schreiben
+                i2c.write(0x02);  // 
+                i2c.write(~5);  // schriebn auf Port 0 den INVERSEN Wert von btn
+            i2c.stop();
+            MotorLf = MotorRf = 1;
+            MotorLr = MotorRr = 0;
+        }
+        else if(taster == 255)
+        {
+            MotorLf = MotorRf = 1;
+            MotorLr = MotorRr = 0;
+        }
+    }
+}
\ No newline at end of file