Full application
Dependencies: mbed libTCS34725 lib_LoRaWAN
main.cpp@6:6ae3c5bca801, 2019-01-25 (annotated)
- Committer:
- dsubotic
- Date:
- Fri Jan 25 16:40:59 2019 +0000
- Revision:
- 6:6ae3c5bca801
- Parent:
- 5:c64f313ca878
- Child:
- 7:d74e195dfa93
RGB fix
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dsubotic | 0:1cadcdcf4521 | 1 | #include "mbed.h" |
dsubotic | 3:67413b100ac3 | 2 | #include "Sht31.h" |
dsubotic | 3:67413b100ac3 | 3 | #include "TCS34725.h" |
dsubotic | 0:1cadcdcf4521 | 4 | |
dsubotic | 2:7040e447d0df | 5 | InterruptIn button1(PG_0); |
dsubotic | 4:5596b326cd34 | 6 | InterruptIn button2(PG_1); |
dsubotic | 2:7040e447d0df | 7 | Serial pc(USBTX, USBRX); |
dsubotic | 2:7040e447d0df | 8 | DigitalOut ledRED(PD_14); |
dsubotic | 4:5596b326cd34 | 9 | DigitalOut ledGreen(PB_0); |
dsubotic | 4:5596b326cd34 | 10 | DigitalOut ledBlue(PD_15); |
dsubotic | 3:67413b100ac3 | 11 | //Sht31 Sht31(PB_9,PB_8); |
dsubotic | 3:67413b100ac3 | 12 | TCS34725 colorSens(PB_9,PB_8); |
dsubotic | 0:1cadcdcf4521 | 13 | |
dsubotic | 3:67413b100ac3 | 14 | float relHumidity, temperature; |
dsubotic | 0:1cadcdcf4521 | 15 | double delay = 0.5; // 500 ms |
dsubotic | 0:1cadcdcf4521 | 16 | |
dsubotic | 2:7040e447d0df | 17 | void BTN1pressed() |
dsubotic | 0:1cadcdcf4521 | 18 | { |
dsubotic | 0:1cadcdcf4521 | 19 | delay = 0.1; // 100 ms |
dsubotic | 0:1cadcdcf4521 | 20 | } |
dsubotic | 0:1cadcdcf4521 | 21 | |
dsubotic | 2:7040e447d0df | 22 | void BTN1released() |
dsubotic | 0:1cadcdcf4521 | 23 | { |
dsubotic | 0:1cadcdcf4521 | 24 | delay = 0.5; // 500 ms |
dsubotic | 0:1cadcdcf4521 | 25 | } |
dsubotic | 0:1cadcdcf4521 | 26 | |
dsubotic | 4:5596b326cd34 | 27 | void BTN2pressed() |
dsubotic | 4:5596b326cd34 | 28 | { |
dsubotic | 4:5596b326cd34 | 29 | //Andere code nodig |
dsubotic | 4:5596b326cd34 | 30 | delay = 0.1; // 100 ms |
dsubotic | 4:5596b326cd34 | 31 | } |
dsubotic | 4:5596b326cd34 | 32 | |
dsubotic | 4:5596b326cd34 | 33 | void BTN2released() |
dsubotic | 4:5596b326cd34 | 34 | { |
dsubotic | 4:5596b326cd34 | 35 | //andere code nodig |
dsubotic | 4:5596b326cd34 | 36 | delay = 0.5; // 500 ms |
dsubotic | 4:5596b326cd34 | 37 | } |
dsubotic | 4:5596b326cd34 | 38 | |
dsubotic | 0:1cadcdcf4521 | 39 | int main() |
dsubotic | 0:1cadcdcf4521 | 40 | { |
dsubotic | 3:67413b100ac3 | 41 | uint16_t r,g,b,c; |
dsubotic | 3:67413b100ac3 | 42 | |
dsubotic | 2:7040e447d0df | 43 | // Assign functions to button1 |
dsubotic | 2:7040e447d0df | 44 | button1.fall(&BTN1pressed); |
dsubotic | 2:7040e447d0df | 45 | button1.rise(&BTN1released); |
dsubotic | 2:7040e447d0df | 46 | |
dsubotic | 4:5596b326cd34 | 47 | // Assign functions to button2 |
dsubotic | 4:5596b326cd34 | 48 | button2.fall(&BTN2pressed); |
dsubotic | 4:5596b326cd34 | 49 | button2.rise(&BTN2released); |
dsubotic | 4:5596b326cd34 | 50 | |
dsubotic | 5:c64f313ca878 | 51 | //Turn off RGB led |
dsubotic | 5:c64f313ca878 | 52 | ledRED = 1; |
dsubotic | 5:c64f313ca878 | 53 | ledGreen = 1; |
dsubotic | 5:c64f313ca878 | 54 | ledBlue = 1; |
dsubotic | 5:c64f313ca878 | 55 | |
dsubotic | 6:6ae3c5bca801 | 56 | |
dsubotic | 2:7040e447d0df | 57 | //serial communication |
dsubotic | 2:7040e447d0df | 58 | pc.baud(115200); |
dsubotic | 2:7040e447d0df | 59 | pc.printf("Welcome at University of Antwerp #STEM2019 \r\n"); |
dsubotic | 3:67413b100ac3 | 60 | |
dsubotic | 3:67413b100ac3 | 61 | if(!colorSens.init(0xD5, 0x03)){ |
dsubotic | 3:67413b100ac3 | 62 | pc.printf("ERROR\n"); //check to see if i2c is responding |
dsubotic | 3:67413b100ac3 | 63 | } |
dsubotic | 0:1cadcdcf4521 | 64 | |
dsubotic | 0:1cadcdcf4521 | 65 | while (1) { |
dsubotic | 3:67413b100ac3 | 66 | //pc.printf("temp: %f \r\n", Sht31.readTemperature()); |
dsubotic | 3:67413b100ac3 | 67 | colorSens.getColor(r,g,b,c); //pass variables by reference... |
dsubotic | 3:67413b100ac3 | 68 | pc.printf("DATA: Red: %d Green: %d Blue: %d Clear: %d \r\n", r, g, b, c); |
dsubotic | 2:7040e447d0df | 69 | ledRED = !ledRED; |
dsubotic | 0:1cadcdcf4521 | 70 | wait(delay); |
dsubotic | 0:1cadcdcf4521 | 71 | } |
dsubotic | 0:1cadcdcf4521 | 72 | } |