Full application

Dependencies:   mbed libTCS34725 lib_LoRaWAN

Committer:
dsubotic
Date:
Wed Jan 16 15:37:20 2019 +0000
Revision:
5:c64f313ca878
Parent:
4:5596b326cd34
Child:
6:6ae3c5bca801
RGB LED standard off

Who changed what in which revision?

UserRevisionLine numberNew 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 2:7040e447d0df 56 //serial communication
dsubotic 2:7040e447d0df 57 pc.baud(115200);
dsubotic 2:7040e447d0df 58 pc.printf("Welcome at University of Antwerp #STEM2019 \r\n");
dsubotic 3:67413b100ac3 59
dsubotic 3:67413b100ac3 60 if(!colorSens.init(0xD5, 0x03)){
dsubotic 3:67413b100ac3 61 pc.printf("ERROR\n"); //check to see if i2c is responding
dsubotic 3:67413b100ac3 62 }
dsubotic 0:1cadcdcf4521 63
dsubotic 0:1cadcdcf4521 64 while (1) {
dsubotic 3:67413b100ac3 65 //pc.printf("temp: %f \r\n", Sht31.readTemperature());
dsubotic 3:67413b100ac3 66 colorSens.getColor(r,g,b,c); //pass variables by reference...
dsubotic 3:67413b100ac3 67 pc.printf("DATA: Red: %d Green: %d Blue: %d Clear: %d \r\n", r, g, b, c);
dsubotic 2:7040e447d0df 68 ledRED = !ledRED;
dsubotic 0:1cadcdcf4521 69 wait(delay);
dsubotic 0:1cadcdcf4521 70 }
dsubotic 0:1cadcdcf4521 71 }