sensor
sample_hardware.cpp@7:d0e445a97c60, 2017-12-06 (annotated)
- Committer:
- noutram
- Date:
- Wed Dec 06 15:57:58 2017 +0000
- Revision:
- 7:d0e445a97c60
- Parent:
- 6:d95616e645bb
- Child:
- 8:df979097cc71
Demo of the LCD, BMP280 and SD Card
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) |
noutram | 5:58ba1a6dbf60 | 31 | puts("**********STARTING POWER ON SELF TEST (POST)**********"); |
noutram | 5:58ba1a6dbf60 | 32 | |
noutram | 5:58ba1a6dbf60 | 33 | //Test LEDs |
noutram | 3:768d30157488 | 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 | } |
noutram | 3:768d30157488 | 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 | 7:d0e445a97c60 | 48 | printf("USER: %d\n\r", onBoardSwitch.read()); |
noutram | 3:768d30157488 | 49 | |
noutram | 3:768d30157488 | 50 | //Output the ADC |
noutram | 3:768d30157488 | 51 | printf("ADC: %f\n\r", adcIn.read()); |
noutram | 5:58ba1a6dbf60 | 52 | |
noutram | 5:58ba1a6dbf60 | 53 | //Read Sensors (I2C) |
noutram | 5:58ba1a6dbf60 | 54 | float temp = sensor.getTemperature(); |
noutram | 5:58ba1a6dbf60 | 55 | float pressure = sensor.getPressure(); |
noutram | 5:58ba1a6dbf60 | 56 | #ifdef BME |
noutram | 5:58ba1a6dbf60 | 57 | float humidity = sensor.getHumidity(); |
noutram | 5:58ba1a6dbf60 | 58 | #endif |
noutram | 5:58ba1a6dbf60 | 59 | |
noutram | 5:58ba1a6dbf60 | 60 | //Display in PuTTY |
noutram | 5:58ba1a6dbf60 | 61 | printf("Temperature: %5.1f\n", temp); |
noutram | 5:58ba1a6dbf60 | 62 | printf("Pressure: %5.1f\n", pressure); |
noutram | 5:58ba1a6dbf60 | 63 | #ifdef BME |
noutram | 5:58ba1a6dbf60 | 64 | printf("Pressure: %5.1f\n", humidity); |
noutram | 5:58ba1a6dbf60 | 65 | #endif |
noutram | 5:58ba1a6dbf60 | 66 | |
noutram | 5:58ba1a6dbf60 | 67 | puts("**********POST END**********"); |
noutram | 5:58ba1a6dbf60 | 68 | |
noutram | 4:d884f14069c6 | 69 | } |
noutram | 4:d884f14069c6 | 70 | |
noutram | 4:d884f14069c6 | 71 | void errorCode(ELEC350_ERROR_CODE err) |
noutram | 4:d884f14069c6 | 72 | { |
noutram | 6:d95616e645bb | 73 | switch (err) { |
noutram | 6:d95616e645bb | 74 | case OK: |
noutram | 6:d95616e645bb | 75 | greenLED = 1; |
noutram | 6:d95616e645bb | 76 | wait(1.0); |
noutram | 6:d95616e645bb | 77 | greenLED = 0; |
noutram | 6:d95616e645bb | 78 | return; |
noutram | 6:d95616e645bb | 79 | case FATAL: |
noutram | 6:d95616e645bb | 80 | while(1) { |
noutram | 6:d95616e645bb | 81 | redLED = 1; |
noutram | 6:d95616e645bb | 82 | wait(0.1); |
noutram | 6:d95616e645bb | 83 | redLED = 0; |
noutram | 6:d95616e645bb | 84 | wait(0.1); |
noutram | 6:d95616e645bb | 85 | } |
noutram | 6:d95616e645bb | 86 | }; |
noutram | 0:6f9f2e93a0be | 87 | } |