Stefan Simbürger / Mbed 2 deprecated Test_13012020

Dependencies:   mbed

Revision:
3:fa690e648ff7
Parent:
2:12ca7ca1b80c
Child:
4:4f42c2344e23
--- a/main.cpp	Mon Jan 13 17:26:41 2020 +0000
+++ b/main.cpp	Mon Jan 13 17:40:05 2020 +0000
@@ -2,6 +2,7 @@
 #define Button1 p14
 
 void nibbleLeds(int value);
+int lauflicht(bool richtung, int time, int&anz);
 BusOut myleds(LED1, LED2, LED3, LED4);
 //DigitalIn button(BUTTON1);
 
@@ -11,6 +12,8 @@
     int anzahl, anz;
     uint8_t value = INIT;
     
+    anzahl = lauflicht(true, 400, anz=0);
+    printf("anzahl= %d\n", anzahl);
     nibbleLeds(value);
     wait(0.1);
 }
@@ -18,4 +21,32 @@
 void nibbleLeds(int value)
 {
     myleds = value%16;
+}
+
+int lauflicht(bool richtung, int time, int&anz)
+{
+    int i;
+    uint8_t lauf = 0x01;
+    
+    if(!richtung)
+        lauf = 0x08;
+    
+    while(1){
+        nibbleLeds(lauf&0x0F);
+        if(richtung){
+            lauf = lauf << 1;
+            
+            if(lauf > 8)
+                lauf = 0x01;
+        }
+        else{
+            lauf = lauf >> 1;
+            if(lauf == 0)
+                lauf = 0x08;
+        }
+        if(button)
+            break;
+        wait_ms(time);
+        anz++;
+    }
 }
\ No newline at end of file