Testprogram

Dependencies:   mbed MPU6050 DS1820

Revision:
3:3dcdaf0d09a1
Parent:
2:0e87ebc53aa8
--- a/main.cpp	Fri Oct 11 09:44:36 2019 +0000
+++ b/main.cpp	Sun Oct 20 13:41:52 2019 +0000
@@ -1,6 +1,6 @@
-// NUClight_TEST1_V3 
-// Diese Software testet die verschiedenen Funktionen des M0 Boards  
-// BULME Graz,     by F. Wolf   05.10.2019
+// Diese Software testet die verschiedenen Funktionen des NUClight V3 Boards  
+// BULME Graz,     
+// by F. Wolf   20.10.2019
 /*
                              PIN-OUT-NUClight
                                 NUCLEO-L432KC
@@ -22,24 +22,14 @@
         
  RGB LED aktiv hight (1)       
  */   
-        
 #include <mbed.h>
 #include "MPU6050.h"
 #include "DS1820.h"
 
-#define DATA_PIN        A0  // DS18B20
-#define MAX_PROBES      2
-
-// ********   Definitionen  **********
-//Serial pc(USBTX, USBRX);
-Serial pc(SERIAL_TX,SERIAL_RX);
+//****** Definitionen **********************
+Serial pc(SERIAL_TX,SERIAL_RX);  //nucleo
 
 // Definition der Taster (Switches)
-/*
-InterruptIn  sw1(A1); //SW1
-InterruptIn  sw2(A2); //SW2 -> sein IO Pin ist laut Schaltplan der P0_15
-InterruptIn  sw3(A3); //SW3
-*/
 InterruptIn sw1(A1); 
 InterruptIn sw2(A2); 
 AnalogIn   ain(A3);
@@ -55,102 +45,85 @@
 DigitalOut led8(D13);   // on Board LED
 
 // RGB 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;          
+PwmOut RGBb(D10); // blaue LED
 
-//mpu6050
-//creating onject of MPU6050 class
+// DS1820 Temperatursensor
+#define DATA_PIN        A0  // DS18B20
+DS1820      ds1820(DATA_PIN);             // create a ds1820 sensor
+
+// GY-521 Module MPU-6050 3-Achsen-Gyroskop + 3 Achsen Accelerometre
 MPU6050 ark(D4,D5); // MPU6050(PinName sda, PinName scl);
-DS1820* probe[MAX_PROBES];
 
 // ********** Deklarationen **************
 void RGBtest();
 void LEDtest();
 void LEDonoff();
 
+// variable
+int a;          
+int num_devices = 0;     
+
 // **********  Hauptprogramm ************** 
 int main()
 {
-    pc.printf("Welcome to NUClight TEST V2 \r\n"); //HTerm Welcome Message  
-    
+    pc.printf("******** TEST-SW *************\r\n"); //HTerm Welcome Message  
+    pc.printf("TEST-SW Welcome to NUClight V3 \r\n"); //HTerm Welcome Message 
+    pc.printf("*******************************\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
-   
-    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)
-    
+        // 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
+        pc.printf("percentage: %3.0f%%\r\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        
+        // reading Temprature
+        float temp = ark.getTemp();
 
-    
-       
-    wait(1);
-             
-          /*************** MPU6050 (gyro) TEST *******************************/        
-     
-        //reading Temprature
-        float temp = ark.getTemp();
-        pc.printf("MPU6050-temprature = %0.2f ^C\r\n",temp);
-        
-        //reading Grometer readings
+        pc.printf("MPU6050-temprature = %0.2f ^C\r\n",temp); 
+        pc.printf("__________________\r\n");
+        //reading Gyrometer readings
         float gyro[3];
         ark.getGyro(gyro);
-        pc.printf("Gyro0=%0.3f,\tGyro1=%0.3f,\tGyro2=%0.3f\r\n",gyro[0],gyro[1],gyro[2]);
-        
+        pc.printf("Gyroscope\r\n");
+        pc.printf("__________________\r\n");
+        pc.printf("Gyro0=%0.3f,  Gyro1=%0.3f,  Gyro2=%0.3f\r\n",gyro[0],gyro[1],gyro[2]);
         //reading Acclerometer readings
         float acce[3];
         ark.getAccelero(acce);
-        pc.printf("Acce0=%0.3f,Acce1=%0.3f,Acce2=%0.3f\r\n",acce[0],acce[1],acce[2]);
-
+        pc.printf("Accelerometer\r\n");
+        pc.printf("__________________\r\n");
+        pc.printf("Acce0=%0.3f,  Acce1=%0.3f,  Acce2=%0.3f\r\n",acce[0],acce[1],acce[2]);
         wait(1); //wait 1000ms
-    
-//DS18B20
+        
+        //DS18B20
+        if(ds1820.begin()) 
+        {
+            ds1820.startConversion();   // start temperature conversion
+            wait(1.0);                  // let DS1820 complete the temperature conversion
+            pc.printf("temprature DS1820 = %3.1f ^C\r\n", ds1820.read(),248);     // read temperature
+            pc.printf("__________________\r\n");
+        }
+        else
+        {
+            pc.printf("No DS1820 sensor found!\r\n");
+        }
+    }
+}
 
-       // define MULTIPLE_PROBES
-        DS1820* probe[MAX_PROBES];
-     
-            // Initialize the probe array to DS1820 objects
-           // int num_devices = 0;
-            while(DS1820::unassignedProbe(DATA_PIN)) {
-                probe[num_devices] = new DS1820(DATA_PIN);
-                num_devices++;
-                if (num_devices == MAX_PROBES)
-                    break;
-            }
-            
-            printf("Found %d device(s)\r\n\n", num_devices);
-      
-                probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
-                for (int i = 0; i<num_devices; i++)
-                    printf("DS18B20-Device %d returns %3.1f oC\r\n", i, probe[i]->temperature());
-                printf("\r\n");
-                wait(1);
-            
-            wait(1);
-            }
-} 
-/**************************************************** Unterprogramme****************************************************/
-/***********************************************************************************************************************/
-           
-/************************** RGB ****************************/
-/***********************************************************/
+
+// **********  Funktionen **************   
+// TEST-RGB
+//------------------------------------
 void RGBtest()
 {
     pc.printf("RGBTEST\r\n"); //HTerm Ausgabe
-    
     LEDtest();
-    
     for (int t=1; t<15;t++)
     {
         RGBr.period_ms(20.0f);  // 20 mili second period
@@ -159,24 +132,21 @@
     }
     
     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)
-    
     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);  //  
@@ -202,13 +172,12 @@
    
 }
 
-/************************** LED ****************************/
-/***********************************************************/
+// TEST-LED
+//------------------------------------
 void LEDtest()
 {
     pc.printf("LAUFLICHT UEBER 8 LED (5-mal) \r\n"); //HTerm Ausgabe
     a=0;
-     
     while (a<5) {   
         led1=1;     //Led1 einschalten
         wait(0.2);
@@ -241,13 +210,12 @@
         led8=1;     //Led3 einschalten
         wait(0.2);
         led8=0;     //Led3 ausschalten
-    
         a++;
         }
 }
 
-/************************ Sensoren *************************/
-/***********************************************************/
+// TEST-LED-on-off
+//------------------------------------
 void LEDonoff()
 {
     led1=!led1;     //Led1 einschalten
@@ -259,6 +227,4 @@
     led7=!led7;     //Led1 einschalten
     led8=!led8;     //Led1 einschalten
 }
-
-/***********/
 /********************   ENDE  ***********************/
\ No newline at end of file