Test ok
Dependencies: mbed MPU6050 DS1820
main.cpp@1:75b533b777ad, 2019-02-13 (annotated)
- Committer:
- wf
- Date:
- Wed Feb 13 12:06:32 2019 +0000
- Revision:
- 1:75b533b777ad
- Parent:
- 0:f007d2f125be
- Child:
- 2:0e87ebc53aa8
Test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wf | 0:f007d2f125be | 1 | // HIMBED _TEST1_V2 |
wf | 1:75b533b777ad | 2 | // TEST 13.02.2019 |
wf | 0:f007d2f125be | 3 | // Diese Software testet die verschiedenen Funktionen des M0 Boards |
wf | 0:f007d2f125be | 4 | // BULME Graz, by F. Wolf 04.02.2019 |
wf | 0:f007d2f125be | 5 | /* |
wf | 0:f007d2f125be | 6 | PIN-OUT-NUClight |
wf | 0:f007d2f125be | 7 | NUCLEO-L432KC |
wf | 0:f007d2f125be | 8 | |-------| |
wf | 0:f007d2f125be | 9 | | | |
wf | 0:f007d2f125be | 10 | | | |
wf | 0:f007d2f125be | 11 | | | |
wf | 0:f007d2f125be | 12 | LED1 <-D2| | |
wf | 0:f007d2f125be | 13 | LED2 <-D3| | |
wf | 0:f007d2f125be | 14 | SDA (I2C) (MPU6050 gyro) <- D4 | | |
wf | 0:f007d2f125be | 15 | SCL (I2C) (MPU6050 gyro) <- D5 | | |
wf | 0:f007d2f125be | 16 | LED3 <-D6| | A3 -> Taster |
wf | 0:f007d2f125be | 17 | | | A2 -> Taster |
wf | 0:f007d2f125be | 18 | | | A1 -> Taster |
wf | 0:f007d2f125be | 19 | | | A0 -> DS18B20 |
wf | 0:f007d2f125be | 20 | RGB-g <- D10| | |
wf | 0:f007d2f125be | 21 | RGB-b <- D11| | |
wf | 0:f007d2f125be | 22 | RGB-r <- D12|-------| |
wf | 0:f007d2f125be | 23 | |
wf | 0:f007d2f125be | 24 | RGB LED aktiv hight (1) |
wf | 0:f007d2f125be | 25 | */ |
wf | 0:f007d2f125be | 26 | |
wf | 0:f007d2f125be | 27 | #include <mbed.h> |
wf | 0:f007d2f125be | 28 | #include "MPU6050.h" |
wf | 0:f007d2f125be | 29 | #include "DS1820.h" |
wf | 0:f007d2f125be | 30 | |
wf | 0:f007d2f125be | 31 | #define DATA_PIN A0 // DS18B20 |
wf | 0:f007d2f125be | 32 | #define MAX_PROBES 2 |
wf | 0:f007d2f125be | 33 | |
wf | 0:f007d2f125be | 34 | // ******** Definitionen ********** |
wf | 0:f007d2f125be | 35 | //Serial pc(USBTX, USBRX); |
wf | 0:f007d2f125be | 36 | Serial pc(SERIAL_TX,SERIAL_RX); |
wf | 0:f007d2f125be | 37 | |
wf | 0:f007d2f125be | 38 | // Definition der Taster (Switches) |
wf | 0:f007d2f125be | 39 | /* |
wf | 0:f007d2f125be | 40 | InterruptIn sw1(A1); //SW1 |
wf | 0:f007d2f125be | 41 | InterruptIn sw2(A2); //SW2 -> sein IO Pin ist laut Schaltplan der P0_15 |
wf | 0:f007d2f125be | 42 | InterruptIn sw3(A3); //SW3 |
wf | 0:f007d2f125be | 43 | */ |
wf | 0:f007d2f125be | 44 | |
wf | 1:75b533b777ad | 45 | |
wf | 1:75b533b777ad | 46 | |
wf | 0:f007d2f125be | 47 | InterruptIn sw1(A1); |
wf | 0:f007d2f125be | 48 | InterruptIn sw2(A2); |
wf | 0:f007d2f125be | 49 | InterruptIn sw3(A3); |
wf | 0:f007d2f125be | 50 | |
wf | 0:f007d2f125be | 51 | |
wf | 0:f007d2f125be | 52 | // Definition der 3 LED's |
wf | 0:f007d2f125be | 53 | DigitalOut led1(D2); |
wf | 0:f007d2f125be | 54 | DigitalOut led2(D3); |
wf | 0:f007d2f125be | 55 | DigitalOut led3(D6); |
wf | 0:f007d2f125be | 56 | |
wf | 0:f007d2f125be | 57 | DigitalOut led4(D13); // on Board LED |
wf | 0:f007d2f125be | 58 | |
wf | 0:f007d2f125be | 59 | // RGB LED |
wf | 0:f007d2f125be | 60 | DigitalOut RGBb(D10); // blaue LED |
wf | 0:f007d2f125be | 61 | DigitalOut RGBg(D11); // grüne LED |
wf | 0:f007d2f125be | 62 | DigitalOut RGBr(D12); // rote LED |
wf | 0:f007d2f125be | 63 | |
wf | 0:f007d2f125be | 64 | int a; |
wf | 0:f007d2f125be | 65 | int num_devices = 0; |
wf | 0:f007d2f125be | 66 | |
wf | 0:f007d2f125be | 67 | //mpu6050 |
wf | 0:f007d2f125be | 68 | //creating onject of MPU6050 class |
wf | 0:f007d2f125be | 69 | MPU6050 ark(D4,D5); // MPU6050(PinName sda, PinName scl); |
wf | 0:f007d2f125be | 70 | |
wf | 0:f007d2f125be | 71 | DS1820* probe[MAX_PROBES]; |
wf | 0:f007d2f125be | 72 | |
wf | 0:f007d2f125be | 73 | // ********** Deklarationen ************** |
wf | 0:f007d2f125be | 74 | void RGBtest(); |
wf | 0:f007d2f125be | 75 | void LEDtest(); |
wf | 0:f007d2f125be | 76 | void LEDonoff(); |
wf | 0:f007d2f125be | 77 | |
wf | 0:f007d2f125be | 78 | // ********** Hauptprogramm ************** |
wf | 0:f007d2f125be | 79 | int main() |
wf | 0:f007d2f125be | 80 | { |
wf | 0:f007d2f125be | 81 | pc.printf("Welcome to NUClight TEST V1 \r\n"); //HTerm Welcome Message |
wf | 0:f007d2f125be | 82 | |
wf | 0:f007d2f125be | 83 | |
wf | 0:f007d2f125be | 84 | while(1) |
wf | 0:f007d2f125be | 85 | { |
wf | 0:f007d2f125be | 86 | // attach the address of the flip function to the rising edge |
wf | 0:f007d2f125be | 87 | sw1.fall(&RGBtest); //RGB-Test Unterprogramm aufrufen |
wf | 0:f007d2f125be | 88 | sw2.fall(&LEDonoff); //LED ON OFF - Test Unterprogramm aufrufen |
wf | 0:f007d2f125be | 89 | sw3.fall(&LEDtest); //LED-Test Unterprogramm aufrufen |
wf | 0:f007d2f125be | 90 | |
wf | 0:f007d2f125be | 91 | |
wf | 0:f007d2f125be | 92 | |
wf | 0:f007d2f125be | 93 | /*************** MPU6050 (gyro) TEST *******************************/ |
wf | 0:f007d2f125be | 94 | |
wf | 0:f007d2f125be | 95 | //reading Temprature |
wf | 0:f007d2f125be | 96 | float temp = ark.getTemp(); |
wf | 0:f007d2f125be | 97 | pc.printf("MPU6050-temprature = %0.2f ^C\r\n",temp); |
wf | 0:f007d2f125be | 98 | |
wf | 0:f007d2f125be | 99 | //reading Grometer readings |
wf | 0:f007d2f125be | 100 | float gyro[3]; |
wf | 0:f007d2f125be | 101 | ark.getGyro(gyro); |
wf | 0:f007d2f125be | 102 | pc.printf("Gyro0=%0.3f,\tGyro1=%0.3f,\tGyro2=%0.3f\r\n",gyro[0],gyro[1],gyro[2]); |
wf | 0:f007d2f125be | 103 | |
wf | 0:f007d2f125be | 104 | //reading Acclerometer readings |
wf | 0:f007d2f125be | 105 | float acce[3]; |
wf | 0:f007d2f125be | 106 | ark.getAccelero(acce); |
wf | 0:f007d2f125be | 107 | pc.printf("Acce0=%0.3f,Acce1=%0.3f,Acce2=%0.3f\r\n",acce[0],acce[1],acce[2]); |
wf | 0:f007d2f125be | 108 | |
wf | 0:f007d2f125be | 109 | wait(1); //wait 1000ms |
wf | 0:f007d2f125be | 110 | |
wf | 0:f007d2f125be | 111 | //DS18B20 |
wf | 0:f007d2f125be | 112 | |
wf | 0:f007d2f125be | 113 | // define MULTIPLE_PROBES |
wf | 0:f007d2f125be | 114 | |
wf | 0:f007d2f125be | 115 | |
wf | 0:f007d2f125be | 116 | DS1820* probe[MAX_PROBES]; |
wf | 0:f007d2f125be | 117 | |
wf | 0:f007d2f125be | 118 | |
wf | 0:f007d2f125be | 119 | // Initialize the probe array to DS1820 objects |
wf | 0:f007d2f125be | 120 | // int num_devices = 0; |
wf | 0:f007d2f125be | 121 | while(DS1820::unassignedProbe(DATA_PIN)) { |
wf | 0:f007d2f125be | 122 | probe[num_devices] = new DS1820(DATA_PIN); |
wf | 0:f007d2f125be | 123 | num_devices++; |
wf | 0:f007d2f125be | 124 | if (num_devices == MAX_PROBES) |
wf | 0:f007d2f125be | 125 | break; |
wf | 0:f007d2f125be | 126 | } |
wf | 0:f007d2f125be | 127 | |
wf | 0:f007d2f125be | 128 | printf("Found %d device(s)\r\n\n", num_devices); |
wf | 0:f007d2f125be | 129 | |
wf | 0:f007d2f125be | 130 | probe[0]->convertTemperature(true, DS1820::all_devices); //Start temperature conversion, wait until ready |
wf | 0:f007d2f125be | 131 | for (int i = 0; i<num_devices; i++) |
wf | 0:f007d2f125be | 132 | printf("DS18B20-Device %d returns %3.1f oC\r\n", i, probe[i]->temperature()); |
wf | 0:f007d2f125be | 133 | printf("\r\n"); |
wf | 0:f007d2f125be | 134 | wait(1); |
wf | 0:f007d2f125be | 135 | |
wf | 0:f007d2f125be | 136 | wait(1); |
wf | 0:f007d2f125be | 137 | } |
wf | 0:f007d2f125be | 138 | } |
wf | 0:f007d2f125be | 139 | /**************************************************** Unterprogramme****************************************************/ |
wf | 0:f007d2f125be | 140 | /***********************************************************************************************************************/ |
wf | 0:f007d2f125be | 141 | |
wf | 0:f007d2f125be | 142 | /************************** RGB ****************************/ |
wf | 0:f007d2f125be | 143 | /***********************************************************/ |
wf | 0:f007d2f125be | 144 | void RGBtest() |
wf | 0:f007d2f125be | 145 | { |
wf | 0:f007d2f125be | 146 | pc.printf("RGBTEST WEIS-ROT-MAGENTA-BLAU-TURKIS-GRUN-GELB\r\n"); //HTerm Ausgabe |
wf | 0:f007d2f125be | 147 | |
wf | 0:f007d2f125be | 148 | //Weiss |
wf | 0:f007d2f125be | 149 | RGBr = 1; // Alle RGB LED EIN |
wf | 0:f007d2f125be | 150 | RGBb = 1; |
wf | 0:f007d2f125be | 151 | RGBg = 1; |
wf | 0:f007d2f125be | 152 | wait(0.2); |
wf | 0:f007d2f125be | 153 | |
wf | 0:f007d2f125be | 154 | //Rot |
wf | 0:f007d2f125be | 155 | RGBb = 0; // Blaue LED ausschalten |
wf | 0:f007d2f125be | 156 | RGBg = 0; // Grune LED ausschalten |
wf | 0:f007d2f125be | 157 | wait(0.2); |
wf | 0:f007d2f125be | 158 | |
wf | 0:f007d2f125be | 159 | //Purple |
wf | 0:f007d2f125be | 160 | RGBb = 1; // Blaue LED einschalten |
wf | 0:f007d2f125be | 161 | wait(0.2); |
wf | 0:f007d2f125be | 162 | |
wf | 0:f007d2f125be | 163 | //Blaue |
wf | 0:f007d2f125be | 164 | RGBr = 0; // Rote LED ausschalten |
wf | 0:f007d2f125be | 165 | wait(0.2); |
wf | 0:f007d2f125be | 166 | |
wf | 0:f007d2f125be | 167 | //Turkis |
wf | 0:f007d2f125be | 168 | RGBg = 1; // Grune LED einschalten |
wf | 0:f007d2f125be | 169 | wait(0.2); |
wf | 0:f007d2f125be | 170 | |
wf | 0:f007d2f125be | 171 | //Grun |
wf | 0:f007d2f125be | 172 | RGBb = 0; // Blaue LED ausschalten |
wf | 0:f007d2f125be | 173 | wait(0.2); |
wf | 0:f007d2f125be | 174 | |
wf | 0:f007d2f125be | 175 | //Gelb |
wf | 0:f007d2f125be | 176 | RGBr = 1; // Rote LED einschalten |
wf | 0:f007d2f125be | 177 | wait(0.2); |
wf | 0:f007d2f125be | 178 | |
wf | 0:f007d2f125be | 179 | //Alle ausschalten |
wf | 0:f007d2f125be | 180 | RGBr = 0; |
wf | 0:f007d2f125be | 181 | RGBb = 0; |
wf | 0:f007d2f125be | 182 | RGBg = 0; |
wf | 0:f007d2f125be | 183 | } |
wf | 0:f007d2f125be | 184 | |
wf | 0:f007d2f125be | 185 | /************************** LED ****************************/ |
wf | 0:f007d2f125be | 186 | /***********************************************************/ |
wf | 0:f007d2f125be | 187 | void LEDtest() |
wf | 0:f007d2f125be | 188 | { |
wf | 0:f007d2f125be | 189 | pc.printf("LAUFLICHT UEBER 3 LED (5-mal) \r\n"); //HTerm Ausgabe |
wf | 0:f007d2f125be | 190 | a=0; |
wf | 0:f007d2f125be | 191 | |
wf | 0:f007d2f125be | 192 | RGBtest(); |
wf | 0:f007d2f125be | 193 | |
wf | 0:f007d2f125be | 194 | |
wf | 0:f007d2f125be | 195 | while (a<5) { |
wf | 0:f007d2f125be | 196 | led1=1; //Led1 einschalten |
wf | 0:f007d2f125be | 197 | wait(0.2); |
wf | 0:f007d2f125be | 198 | led1=0; //Led1 ausschalten |
wf | 0:f007d2f125be | 199 | |
wf | 0:f007d2f125be | 200 | led2=1; //Led2 einschalten |
wf | 0:f007d2f125be | 201 | wait(0.2); |
wf | 0:f007d2f125be | 202 | led2=0; //Led2 ausschalten |
wf | 0:f007d2f125be | 203 | |
wf | 0:f007d2f125be | 204 | led3=1; //Led3 einschalten |
wf | 0:f007d2f125be | 205 | wait(0.2); |
wf | 0:f007d2f125be | 206 | led3=0; //Led3 ausschalten |
wf | 0:f007d2f125be | 207 | |
wf | 0:f007d2f125be | 208 | led4=!led4; |
wf | 0:f007d2f125be | 209 | a++; |
wf | 0:f007d2f125be | 210 | } |
wf | 0:f007d2f125be | 211 | } |
wf | 0:f007d2f125be | 212 | |
wf | 0:f007d2f125be | 213 | /************************ Sensoren *************************/ |
wf | 0:f007d2f125be | 214 | /***********************************************************/ |
wf | 0:f007d2f125be | 215 | void LEDonoff() |
wf | 0:f007d2f125be | 216 | { |
wf | 0:f007d2f125be | 217 | /* |
wf | 0:f007d2f125be | 218 | led1=!led1; //Led1 einschalten |
wf | 0:f007d2f125be | 219 | led2=!led2; //Led1 einschalten |
wf | 0:f007d2f125be | 220 | led3=!led3; //Led1 einschalten |
wf | 0:f007d2f125be | 221 | */ |
wf | 0:f007d2f125be | 222 | |
wf | 0:f007d2f125be | 223 | led4=!led4; //Led1 einschalten |
wf | 0:f007d2f125be | 224 | } |
wf | 0:f007d2f125be | 225 | |
wf | 0:f007d2f125be | 226 | /***********/ |
wf | 0:f007d2f125be | 227 | /******************** ENDE ***********************/ |