sensor
sample_hardware.cpp@9:5c695a388b14, 2018-11-30 (annotated)
- Committer:
- Joelpallent
- Date:
- Fri Nov 30 13:11:51 2018 +0000
- Revision:
- 9:5c695a388b14
- Parent:
- 6:d95616e645bb
sensor;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
noutram | 0:6f9f2e93a0be | 1 | #include "mbed.h" |
noutram | 0:6f9f2e93a0be | 2 | #include "sample_hardware.hpp" |
noutram | 0:6f9f2e93a0be | 3 | |
noutram | 0:6f9f2e93a0be | 4 | #define RED_DONE 1 |
noutram | 0:6f9f2e93a0be | 5 | #define YELLOW_DONE 2 |
noutram | 0:6f9f2e93a0be | 6 | |
noutram | 0:6f9f2e93a0be | 7 | //Digital outputs |
noutram | 0:6f9f2e93a0be | 8 | DigitalOut onBoardLED(LED1); |
noutram | 0:6f9f2e93a0be | 9 | DigitalOut redLED(PE_15); |
noutram | 0:6f9f2e93a0be | 10 | DigitalOut yellowLED(PB_10); |
noutram | 0:6f9f2e93a0be | 11 | DigitalOut greenLED(PB_11); |
noutram | 0:6f9f2e93a0be | 12 | |
noutram | 0:6f9f2e93a0be | 13 | //Inputs |
noutram | 0:6f9f2e93a0be | 14 | DigitalIn onBoardSwitch(USER_BUTTON); |
noutram | 0:6f9f2e93a0be | 15 | DigitalIn SW1(PE_12); |
noutram | 0:6f9f2e93a0be | 16 | DigitalIn SW2(PE_14); |
noutram | 0:6f9f2e93a0be | 17 | //Serial pc(USBTX, USBRX); |
noutram | 2:24eb98cf2376 | 18 | AnalogIn adcIn(PA_0); |
noutram | 0:6f9f2e93a0be | 19 | |
noutram | 5:58ba1a6dbf60 | 20 | //Environmental Sensor driver |
noutram | 5:58ba1a6dbf60 | 21 | #ifdef BME |
noutram | 5:58ba1a6dbf60 | 22 | BME280 sensor(D14, D15); |
noutram | 5:58ba1a6dbf60 | 23 | #else |
noutram | 5:58ba1a6dbf60 | 24 | BMP280 sensor(D14, D15); |
noutram | 5:58ba1a6dbf60 | 25 | #endif |
noutram | 3:768d30157488 | 26 | |
noutram | 0:6f9f2e93a0be | 27 | //POWER ON SELF TEST |
noutram | 0:6f9f2e93a0be | 28 | void post() |
noutram | 0:6f9f2e93a0be | 29 | { |
noutram | 0:6f9f2e93a0be | 30 | //POWER ON TEST (POT) |
Joelpallent | 9:5c695a388b14 | 31 | // puts("**********STARTING POWER ON SELF TEST (POST)**********"); |
noutram | 5:58ba1a6dbf60 | 32 | |
noutram | 5:58ba1a6dbf60 | 33 | //Test LEDs |
Joelpallent | 9:5c695a388b14 | 34 | /* puts("ALL LEDs should be blinking"); |
noutram | 0:6f9f2e93a0be | 35 | for (unsigned int n=0; n<10; n++) { |
noutram | 0:6f9f2e93a0be | 36 | redLED = 1; |
noutram | 0:6f9f2e93a0be | 37 | yellowLED = 1; |
noutram | 0:6f9f2e93a0be | 38 | greenLED = 1; |
noutram | 0:6f9f2e93a0be | 39 | wait(0.05); |
noutram | 0:6f9f2e93a0be | 40 | redLED = 0; |
noutram | 0:6f9f2e93a0be | 41 | yellowLED = 0; |
noutram | 0:6f9f2e93a0be | 42 | greenLED = 0; |
noutram | 0:6f9f2e93a0be | 43 | wait(0.05); |
noutram | 3:768d30157488 | 44 | } |
Joelpallent | 9:5c695a388b14 | 45 | */ |
noutram | 3:768d30157488 | 46 | //Output the switch states (hold them down to test) |
noutram | 3:768d30157488 | 47 | printf("SW1: %d\tSW2: %d\n\r", SW1.read(), SW2.read()); |
noutram | 3:768d30157488 | 48 | |
noutram | 3:768d30157488 | 49 | //Output the ADC |
noutram | 3:768d30157488 | 50 | printf("ADC: %f\n\r", adcIn.read()); |
noutram | 5:58ba1a6dbf60 | 51 | |
noutram | 5:58ba1a6dbf60 | 52 | //Read Sensors (I2C) |
noutram | 5:58ba1a6dbf60 | 53 | float temp = sensor.getTemperature(); |
Joelpallent | 9:5c695a388b14 | 54 | // float pressure = sensor.getPressure(); |
noutram | 5:58ba1a6dbf60 | 55 | #ifdef BME |
noutram | 5:58ba1a6dbf60 | 56 | float humidity = sensor.getHumidity(); |
noutram | 5:58ba1a6dbf60 | 57 | #endif |
noutram | 5:58ba1a6dbf60 | 58 | |
noutram | 5:58ba1a6dbf60 | 59 | //Display in PuTTY |
Joelpallent | 9:5c695a388b14 | 60 | printf("Temperature: %5.1f\n\r", temp); |
Joelpallent | 9:5c695a388b14 | 61 | // printf("Pressure: %5.1f\n\n\r", pressure); |
noutram | 5:58ba1a6dbf60 | 62 | #ifdef BME |
Joelpallent | 9:5c695a388b14 | 63 | printf("humidity: %5.1f\n\r", humidity); |
noutram | 5:58ba1a6dbf60 | 64 | #endif |
noutram | 5:58ba1a6dbf60 | 65 | |
Joelpallent | 9:5c695a388b14 | 66 | // puts("**********POST END**********\n\r"); |
noutram | 5:58ba1a6dbf60 | 67 | |
noutram | 4:d884f14069c6 | 68 | } |
noutram | 4:d884f14069c6 | 69 | |
noutram | 4:d884f14069c6 | 70 | void errorCode(ELEC350_ERROR_CODE err) |
noutram | 4:d884f14069c6 | 71 | { |
noutram | 6:d95616e645bb | 72 | switch (err) { |
noutram | 6:d95616e645bb | 73 | case OK: |
noutram | 6:d95616e645bb | 74 | greenLED = 1; |
noutram | 6:d95616e645bb | 75 | wait(1.0); |
noutram | 6:d95616e645bb | 76 | greenLED = 0; |
noutram | 6:d95616e645bb | 77 | return; |
noutram | 6:d95616e645bb | 78 | case FATAL: |
noutram | 6:d95616e645bb | 79 | while(1) { |
noutram | 6:d95616e645bb | 80 | redLED = 1; |
noutram | 6:d95616e645bb | 81 | wait(0.1); |
noutram | 6:d95616e645bb | 82 | redLED = 0; |
noutram | 6:d95616e645bb | 83 | wait(0.1); |
noutram | 6:d95616e645bb | 84 | } |
noutram | 6:d95616e645bb | 85 | }; |
noutram | 0:6f9f2e93a0be | 86 | } |