Full application

Dependencies:   mbed libTCS34725 lib_LoRaWAN

Revision:
7:d74e195dfa93
Parent:
6:6ae3c5bca801
diff -r 6ae3c5bca801 -r d74e195dfa93 main.cpp
--- a/main.cpp	Fri Jan 25 16:40:59 2019 +0000
+++ b/main.cpp	Tue Jan 28 09:55:58 2020 +0000
@@ -1,6 +1,6 @@
 #include "mbed.h"
-#include "Sht31.h"
 #include "TCS34725.h"
+#include "LoRaWAN.h"
 
 InterruptIn button1(PG_0);
 InterruptIn button2(PG_1);
@@ -8,15 +8,17 @@
 DigitalOut ledRED(PD_14);
 DigitalOut ledGreen(PB_0);
 DigitalOut ledBlue(PD_15);
-//Sht31 Sht31(PB_9,PB_8);
-TCS34725 colorSens(PB_9,PB_8);
 
-float relHumidity, temperature;
+TCS34725 colorSens(PB_9,PB_8);
+LoRaWAN OCTA_LoRa(PC_12, PD_2);
+
 double delay = 0.5; // 500 ms
+uint16_t r,g,b,c;
 
 void BTN1pressed()
 {
     delay = 0.1; // 100 ms
+    
 }
 
 void BTN1released()
@@ -27,18 +29,28 @@
 void BTN2pressed()
 {
     //Andere code nodig
-    delay = 0.1; // 100 ms
+    
 }
 
 void BTN2released()
 {
-    //andere code nodig
-    delay = 0.5; // 500 ms
+    char data[50];
+    char msg[25]= "AT+SENDB="; 
+    sprintf(msg+9,  "%04X",  r);
+    sprintf(msg+13, "%04X",  g);
+    sprintf(msg+17, "%04X",  b);
+    sprintf(msg+21, "%04X",  c);
+    bool ok = OCTA_LoRa.sendMessage(msg);
+    OCTA_LoRa.recieveData(data, 19);    // Read data
+    wait(0.2);
+    pc.printf("Received:%s \r\n", data);
+    
 }
 
 int main()
 {
-    uint16_t r,g,b,c;
+    
+    //char data[202];
     
     // Assign functions to button1 
     button1.fall(&BTN1pressed);
@@ -53,20 +65,24 @@
     ledGreen = 1;
     ledBlue = 1;
     
-    
     //serial communication
     pc.baud(115200);
-    pc.printf("Welcome at University of Antwerp #STEM2019 \r\n");
+    pc.printf("Welcome at University of Antwerp #STEM2020 \r\n");
     
+    //initialization of the color sensor
     if(!colorSens.init(0xD5, 0x03)){
-        pc.printf("ERROR\n"); //check to see if i2c is responding
+        pc.printf("ERROR: SENSOR\r\n"); //check to see if i2c is responding
     }
+    //initialization of the LoRaWAN module
+    if(!OCTA_LoRa.init()){
+        pc.printf("ERROR: LoRaWAN module\r\n");
+    }
+    
 
     while (1) {
-        //pc.printf("temp: %f \r\n", Sht31.readTemperature());
         colorSens.getColor(r,g,b,c); //pass variables by reference...
-        pc.printf("DATA: Red: %d Green: %d Blue: %d Clear: %d \r\n", r, g, b, c);
-        ledRED = !ledRED;
+        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
+        ledRED = !ledRED; //Toggle LED
         wait(delay);
     }
 }