verschiedene Funktionen mit Interrupt

Dependencies:   mbed

Revision:
0:1c9547d9c57c
diff -r 000000000000 -r 1c9547d9c57c main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 22 15:42:27 2020 +0000
@@ -0,0 +1,118 @@
+#include "mbed.h"
+
+DigitalOut myled(LED1);
+
+//        D13   A6   D12   D11   D9    D6    D3     D2
+BusOut lb(PB_3,PA_7,PB_4, PB_5, PA_8, PB_1, PB_0, PA_12);
+DigitalOut red (D1), green(D0), blue(D10);
+
+DigitalIn btn1(A1);
+DigitalIn btn2(A2);
+
+InterruptIn sw1(A1);
+
+void runlightright();
+void runlightleft();
+void btntest();
+void BtnLedTest1();
+void RGB();
+void interrupt();
+void runlightstep(); 
+
+int main() {
+   //runlightright();
+   //runlightleft();
+   //btntest();
+   //RGB();
+   /*while(1){
+   BtnLedTest1();
+   }*/
+   sw1.rise(interrupt);
+   
+   while(1)
+   {}
+}
+
+//LEDs leuchten abwechselnd von Rechts nach Links
+void runlightright()
+{
+    while(1){
+    lb=1;
+    for(int i = 0; i <= 8; i++)
+    {
+        wait_ms(200);
+        lb = lb << 1;
+    }
+    
+    }
+}
+
+//LEDs leuchten abwechselnd von Links nach Rechts
+void runlightleft()
+{
+    while(1){
+    lb=128;
+    for(int i = 0; i <= 8; i++)
+    {
+        wait_ms(200);
+        lb = lb >> 1;
+    }
+    }   
+}
+void btntest(){
+    
+    while(1){
+    if(btn1.read() == 0)
+    {
+        lb = lb | 0xFF;
+    }
+    if(btn2.read() == 0)
+    {
+        lb = lb | 2;
+    }
+    else
+    {
+        lb = 0;
+    }
+    }
+}
+
+void BtnLedTest1()
+{    
+    if( btn1.read()==0 )        
+        lb = lb | 0x0F;
+    if( btn2.read()==0 )
+        lb = lb | 0xF0;
+    wait_ms(200);
+    lb = 0;
+    wait_ms(200);
+}
+
+void RGB()
+{
+    while(1)
+    {
+        red =1;
+        wait_ms(5); 
+        green = 1;
+        wait_ms(5);  
+        
+        red =0;
+        wait_ms(5); 
+        green = 0;
+        wait_ms(5);                
+    }
+}
+void interrupt()
+{
+    if(sw1.read() == 0)
+    runlightstep();
+}
+void runlightstep()
+{
+    if(lb==0)
+     lb = 1;
+    else 
+     lb = lb << 1;
+    
+}