![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Test ok
Dependencies: mbed MPU6050 DS1820
main.cpp
- Committer:
- wf
- Date:
- 2019-10-11
- Revision:
- 2:0e87ebc53aa8
- Parent:
- 1:75b533b777ad
- Child:
- 3:3dcdaf0d09a1
File content as of revision 2:0e87ebc53aa8:
// NUClight_TEST1_V3 // Diese Software testet die verschiedenen Funktionen des M0 Boards // BULME Graz, by F. Wolf 05.10.2019 /* PIN-OUT-NUClight NUCLEO-L432KC 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) */ #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); // 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); // Definition der 8 LED's DigitalOut led1(D2); DigitalOut led2(D3); DigitalOut led3(D6); DigitalOut led4(D9); DigitalOut led5(D11); DigitalOut led6(D12); DigitalOut led7(A6); 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; //mpu6050 //creating onject of MPU6050 class MPU6050 ark(D4,D5); // MPU6050(PinName sda, PinName scl); DS1820* probe[MAX_PROBES]; // ********** Deklarationen ************** void RGBtest(); void LEDtest(); void LEDonoff(); // ********** Hauptprogramm ************** int main() { 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 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 *******************************/ //reading Temprature float temp = ark.getTemp(); pc.printf("MPU6050-temprature = %0.2f ^C\r\n",temp); //reading Grometer 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]); //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]); wait(1); //wait 1000ms //DS18B20 // 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 ****************************/ /***********************************************************/ 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 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) 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 8 LED (5-mal) \r\n"); //HTerm Ausgabe a=0; while (a<5) { led1=1; //Led1 einschalten wait(0.2); led1=0; //Led1 ausschalten led2=1; //Led2 einschalten wait(0.2); led2=0; //Led2 ausschalten led3=1; //Led3 einschalten wait(0.2); led3=0; //Led3 ausschalten 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++; } } /************************ Sensoren *************************/ /***********************************************************/ void LEDonoff() { led1=!led1; //Led1 einschalten led2=!led2; //Led1 einschalten led3=!led3; //Led1 einschalten led4=!led4; //Led1 einschalten led5=!led5; //Led1 einschalten led6=!led6; //Led1 einschalten led7=!led7; //Led1 einschalten led8=!led8; //Led1 einschalten } /***********/ /******************** ENDE ***********************/