Test ok

Dependencies:   mbed MPU6050 DS1820

Revision:
2:0e87ebc53aa8
Parent:
1:75b533b777ad
Child:
3:3dcdaf0d09a1
diff -r 75b533b777ad -r 0e87ebc53aa8 main.cpp
--- a/main.cpp	Wed Feb 13 12:06:32 2019 +0000
+++ b/main.cpp	Fri Oct 11 09:44:36 2019 +0000
@@ -1,25 +1,24 @@
-// HIMBED _TEST1_V2 
-// TEST 13.02.2019
+// NUClight_TEST1_V3 
 // Diese Software testet die verschiedenen Funktionen des M0 Boards  
-// BULME Graz,     by F. Wolf   04.02.2019
+// BULME Graz,     by F. Wolf   05.10.2019
 /*
                              PIN-OUT-NUClight
                                 NUCLEO-L432KC
-                                 |-------|
-                                 |       |
-                                 |       |
-                                 |       |
-                        LED1 <-D2|       |
-                        LED2 <-D3|       |
-SDA (I2C)  (MPU6050 gyro) <- D4  |       | 
-SCL (I2C)  (MPU6050 gyro) <- D5  |       |
-                        LED3 <-D6|       | A3 -> Taster
-                                 |       | A2 -> Taster
-                                 |       | A1 -> Taster
-                                 |       | A0 -> DS18B20
-                     RGB-g <- D10|       |
-                     RGB-b <- D11|       |
-                     RGB-r <- D12|-------|
+                     RGB-rot   D1|-------| VIn
+                     RGB-gruen D0|       | GND
+                             NRST|       | RST
+                              GND|       | 5V0
+                        LED1 <-D2|       | A7
+                        LED2 <-D3|       | A6 -> LED7
+SDA (I2C)  (MPU6050 gyro)   <- D4|       | A5
+SCL (I2C)  (MPU6050 gyro)   <- D5|       | A4
+                        LED3 <-D6|       | A3 -> POTI
+                            nc D7|       | A2 -> Taster
+                            nc D8|       | A1 -> Taster
+                         LED4  D9|       | A0 -> DS18B20
+                  RGB-blau <- D10|       | ARF
+                      LED5 <- D11|       | 3V0
+                      LED6 <- D12|-------| D13 -> LED8
         
  RGB LED aktiv hight (1)       
  */   
@@ -41,25 +40,27 @@
 InterruptIn  sw2(A2); //SW2 -> sein IO Pin ist laut Schaltplan der P0_15
 InterruptIn  sw3(A3); //SW3
 */
-
-
-
 InterruptIn sw1(A1); 
 InterruptIn sw2(A2); 
-InterruptIn sw3(A3); 
+AnalogIn   ain(A3);
 
-
-// Definition der 3 LED's
+// Definition der 8 LED's
 DigitalOut led1(D2);
 DigitalOut led2(D3);
 DigitalOut led3(D6);
-
-DigitalOut led4(D13);  // on Board LED
+DigitalOut led4(D9);
+DigitalOut led5(D11);
+DigitalOut led6(D12);
+DigitalOut led7(A6);
+DigitalOut led8(D13);   // on Board LED
 
 // RGB LED
-DigitalOut RGBb(D10);  // blaue LED
-DigitalOut RGBg(D11);  // grüne LED 
-DigitalOut RGBr(D12);  // rote  LED
+//DigitalOut RGBb(D0);  // blaue LED
+//DigitalOut RGBg(D1);  // grüne LED 
+//DigitalOut RGBr(D12);  // rote  LED
+PwmOut RGBg(D0);  // gruen LED
+PwmOut RGBr(D1);  // rote LED
+PwmOut RGBb(D10);  // blaue LED
 
 int a;          
 int num_devices = 0;          
@@ -67,7 +68,6 @@
 //mpu6050
 //creating onject of MPU6050 class
 MPU6050 ark(D4,D5); // MPU6050(PinName sda, PinName scl);
-
 DS1820* probe[MAX_PROBES];
 
 // ********** Deklarationen **************
@@ -78,17 +78,24 @@
 // **********  Hauptprogramm ************** 
 int main()
 {
-    pc.printf("Welcome to NUClight TEST V1 \r\n"); //HTerm Welcome Message  
-    
+    pc.printf("Welcome to NUClight TEST V2 \r\n"); //HTerm Welcome Message  
     
     while(1)
     {
     // attach the address of the flip function to the rising edge
     sw1.fall(&RGBtest);      //RGB-Test Unterprogramm aufrufen
     sw2.fall(&LEDonoff);     //LED ON OFF - Test Unterprogramm aufrufen
-    sw3.fall(&LEDtest);      //LED-Test Unterprogramm aufrufen
    
+    pc.printf("percentage: %3.3f%%\n", ain.read()*100.0f);  
+  
+    
+    RGBr.period_ms(20.0f);  // 20 mili second period
+    RGBr.pulsewidth_ms(ain.read()*10.0f);  //  5 mili second pulse (on)
+    
 
+    
+       
+    wait(1);
              
           /*************** MPU6050 (gyro) TEST *******************************/        
      
@@ -111,10 +118,7 @@
 //DS18B20
 
        // define MULTIPLE_PROBES
-     
-         
         DS1820* probe[MAX_PROBES];
-         
      
             // Initialize the probe array to DS1820 objects
            // int num_devices = 0;
@@ -143,55 +147,68 @@
 /***********************************************************/
 void RGBtest()
 {
-    pc.printf("RGBTEST WEIS-ROT-MAGENTA-BLAU-TURKIS-GRUN-GELB\r\n"); //HTerm Ausgabe
+    pc.printf("RGBTEST\r\n"); //HTerm Ausgabe
+    
+    LEDtest();
+    
+    for (int t=1; t<15;t++)
+    {
+        RGBr.period_ms(20.0f);  // 20 mili second period
+        RGBr.pulsewidth_ms(t);  //  5 mili second pulse (on)
+        wait(0.3);
+    }
+    
+    RGBr.pulsewidth_ms(0);  //  5 mili second pulse (on) 
+    
+    for (int t=1; t<15;t++)
+    {
+        RGBg.period_ms(20.0f);  // 20 mili second period
+        RGBg.pulsewidth_ms(t);  //  5 mili second pulse (on)
+        wait(0.3);
+    }
+    
+    RGBr.pulsewidth_ms(0);  //  5 mili second pulse (on)
+    RGBg.pulsewidth_ms(0);  //  5 mili second pulse (on)
     
-        //Weiss
-        RGBr = 1;   // Alle RGB LED EIN
-        RGBb = 1;
-        RGBg = 1;
-        wait(0.2); 
-        
-        //Rot
-        RGBb = 0; // Blaue LED ausschalten
-        RGBg = 0; // Grune LED ausschalten
-        wait(0.2);
-        
-        //Purple
-        RGBb = 1; // Blaue LED einschalten
-        wait(0.2);
-        
-        //Blaue
-        RGBr = 0; // Rote LED ausschalten
-        wait(0.2);
-        
-        //Turkis
-        RGBg = 1; // Grune LED einschalten
-        wait(0.2);
-        
-        //Grun
-        RGBb = 0; // Blaue LED ausschalten
-        wait(0.2);
-        
-        //Gelb
-        RGBr = 1; // Rote LED einschalten
-        wait(0.2);
-        
-        //Alle ausschalten
-        RGBr = 0;  
-        RGBb = 0;
-        RGBg = 0;
+    for (int t=1; t<15;t++)
+    {
+        RGBb.period_ms(20.0f);  // 20 mili second period
+        RGBb.pulsewidth_ms(t);  //  5 mili second pulse (on)
+        wait(0.3);
+    }
+    
+    wait(1);
+    RGBr.pulsewidth_ms(0);  //  RGB-LED off
+    RGBg.pulsewidth_ms(0);  //  
+    RGBb.pulsewidth_ms(0);  //
+    
+    int rr=(rand()%15);
+    int rg=(rand()%15);
+    int rb=(rand()%15);
+    
+    RGBr.period_ms(20.0f);  // 20 mili second period
+    RGBr.pulsewidth_ms(rr);  //  5 mili second pulse (on)
+    
+    RGBg.period_ms(20.0f);  // 20 mili second period
+    RGBg.pulsewidth_ms(rg);  //  5 mili second pulse (on)
+    
+    RGBb.period_ms(20.0f);  // 20 mili second period
+    RGBb.pulsewidth_ms(rb);  //  5 mili second pulse (on)
+    
+    wait(1);
+    RGBr.pulsewidth_ms(0);  //  RGB-LED off
+    RGBg.pulsewidth_ms(0);  //  
+    RGBb.pulsewidth_ms(0);  //
+   
 }
 
 /************************** LED ****************************/
 /***********************************************************/
 void LEDtest()
 {
-    pc.printf("LAUFLICHT UEBER 3 LED (5-mal) \r\n"); //HTerm Ausgabe
+    pc.printf("LAUFLICHT UEBER 8 LED (5-mal) \r\n"); //HTerm Ausgabe
     a=0;
      
-    RGBtest(); 
- 
-    
     while (a<5) {   
         led1=1;     //Led1 einschalten
         wait(0.2);
@@ -205,7 +222,26 @@
         wait(0.2);
         led3=0;     //Led3 ausschalten
         
-        led4=!led4;
+        led4=1;     //Led1 einschalten
+        wait(0.2);
+        led4=0;     //Led1 ausschalten
+        
+        led5=1;     //Led2 einschalten
+        wait(0.2);
+        led5=0;     //Led2 ausschalten
+        
+        led6=1;     //Led3 einschalten
+        wait(0.2);
+        led6=0;     //Led3 ausschalten
+        
+        led7=1;     //Led2 einschalten
+        wait(0.2);
+        led7=0;     //Led2 ausschalten
+        
+        led8=1;     //Led3 einschalten
+        wait(0.2);
+        led8=0;     //Led3 ausschalten
+    
         a++;
         }
 }
@@ -214,13 +250,14 @@
 /***********************************************************/
 void LEDonoff()
 {
-    /*
     led1=!led1;     //Led1 einschalten
     led2=!led2;     //Led1 einschalten
     led3=!led3;     //Led1 einschalten
-*/
-
-  led4=!led4;     //Led1 einschalten
+    led4=!led4;     //Led1 einschalten
+    led5=!led5;     //Led1 einschalten
+    led6=!led6;     //Led1 einschalten
+    led7=!led7;     //Led1 einschalten
+    led8=!led8;     //Led1 einschalten
 }
 
 /***********/