Full application

Dependencies:   mbed libTCS34725 lib_LoRaWAN

Committer:
dsubotic
Date:
Tue Jan 28 09:58:08 2020 +0000
Revision:
8:3af9530bd51e
Parent:
7:d74e195dfa93
STEM 2020 application

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dsubotic 0:1cadcdcf4521 1 #include "mbed.h"
dsubotic 3:67413b100ac3 2 #include "TCS34725.h"
dsubotic 7:d74e195dfa93 3 #include "LoRaWAN.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 0:1cadcdcf4521 11
dsubotic 7:d74e195dfa93 12 TCS34725 colorSens(PB_9,PB_8);
dsubotic 7:d74e195dfa93 13 LoRaWAN OCTA_LoRa(PC_12, PD_2);
dsubotic 7:d74e195dfa93 14
dsubotic 0:1cadcdcf4521 15 double delay = 0.5; // 500 ms
dsubotic 7:d74e195dfa93 16 uint16_t r,g,b,c;
dsubotic 0:1cadcdcf4521 17
dsubotic 2:7040e447d0df 18 void BTN1pressed()
dsubotic 0:1cadcdcf4521 19 {
dsubotic 0:1cadcdcf4521 20 delay = 0.1; // 100 ms
dsubotic 7:d74e195dfa93 21
dsubotic 0:1cadcdcf4521 22 }
dsubotic 0:1cadcdcf4521 23
dsubotic 2:7040e447d0df 24 void BTN1released()
dsubotic 0:1cadcdcf4521 25 {
dsubotic 0:1cadcdcf4521 26 delay = 0.5; // 500 ms
dsubotic 0:1cadcdcf4521 27 }
dsubotic 0:1cadcdcf4521 28
dsubotic 4:5596b326cd34 29 void BTN2pressed()
dsubotic 4:5596b326cd34 30 {
dsubotic 4:5596b326cd34 31 //Andere code nodig
dsubotic 7:d74e195dfa93 32
dsubotic 4:5596b326cd34 33 }
dsubotic 4:5596b326cd34 34
dsubotic 4:5596b326cd34 35 void BTN2released()
dsubotic 4:5596b326cd34 36 {
dsubotic 7:d74e195dfa93 37 char data[50];
dsubotic 7:d74e195dfa93 38 char msg[25]= "AT+SENDB=";
dsubotic 7:d74e195dfa93 39 sprintf(msg+9, "%04X", r);
dsubotic 7:d74e195dfa93 40 sprintf(msg+13, "%04X", g);
dsubotic 7:d74e195dfa93 41 sprintf(msg+17, "%04X", b);
dsubotic 7:d74e195dfa93 42 sprintf(msg+21, "%04X", c);
dsubotic 7:d74e195dfa93 43 bool ok = OCTA_LoRa.sendMessage(msg);
dsubotic 7:d74e195dfa93 44 OCTA_LoRa.recieveData(data, 19); // Read data
dsubotic 7:d74e195dfa93 45 wait(0.2);
dsubotic 7:d74e195dfa93 46 pc.printf("Received:%s \r\n", data);
dsubotic 7:d74e195dfa93 47
dsubotic 4:5596b326cd34 48 }
dsubotic 4:5596b326cd34 49
dsubotic 0:1cadcdcf4521 50 int main()
dsubotic 0:1cadcdcf4521 51 {
dsubotic 7:d74e195dfa93 52
dsubotic 7:d74e195dfa93 53 //char data[202];
dsubotic 3:67413b100ac3 54
dsubotic 2:7040e447d0df 55 // Assign functions to button1
dsubotic 2:7040e447d0df 56 button1.fall(&BTN1pressed);
dsubotic 2:7040e447d0df 57 button1.rise(&BTN1released);
dsubotic 2:7040e447d0df 58
dsubotic 4:5596b326cd34 59 // Assign functions to button2
dsubotic 4:5596b326cd34 60 button2.fall(&BTN2pressed);
dsubotic 4:5596b326cd34 61 button2.rise(&BTN2released);
dsubotic 4:5596b326cd34 62
dsubotic 5:c64f313ca878 63 //Turn off RGB led
dsubotic 5:c64f313ca878 64 ledRED = 1;
dsubotic 5:c64f313ca878 65 ledGreen = 1;
dsubotic 5:c64f313ca878 66 ledBlue = 1;
dsubotic 5:c64f313ca878 67
dsubotic 2:7040e447d0df 68 //serial communication
dsubotic 2:7040e447d0df 69 pc.baud(115200);
dsubotic 7:d74e195dfa93 70 pc.printf("Welcome at University of Antwerp #STEM2020 \r\n");
dsubotic 3:67413b100ac3 71
dsubotic 7:d74e195dfa93 72 //initialization of the color sensor
dsubotic 3:67413b100ac3 73 if(!colorSens.init(0xD5, 0x03)){
dsubotic 7:d74e195dfa93 74 pc.printf("ERROR: SENSOR\r\n"); //check to see if i2c is responding
dsubotic 3:67413b100ac3 75 }
dsubotic 7:d74e195dfa93 76 //initialization of the LoRaWAN module
dsubotic 7:d74e195dfa93 77 if(!OCTA_LoRa.init()){
dsubotic 7:d74e195dfa93 78 pc.printf("ERROR: LoRaWAN module\r\n");
dsubotic 7:d74e195dfa93 79 }
dsubotic 7:d74e195dfa93 80
dsubotic 0:1cadcdcf4521 81
dsubotic 0:1cadcdcf4521 82 while (1) {
dsubotic 3:67413b100ac3 83 colorSens.getColor(r,g,b,c); //pass variables by reference...
dsubotic 7:d74e195dfa93 84 pc.printf("DATA: Red: %d Green: %d Blue: %d Clear: %d \r\n", r, g, b, c); // Send sensor data on USB cable to PC
dsubotic 7:d74e195dfa93 85 ledRED = !ledRED; //Toggle LED
dsubotic 0:1cadcdcf4521 86 wait(delay);
dsubotic 0:1cadcdcf4521 87 }
dsubotic 0:1cadcdcf4521 88 }