Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed libTCS34725 lib_LoRaWAN
main.cpp
00001 #include "mbed.h" 00002 #include "TCS34725.h" 00003 #include "LoRaWAN.h" 00004 00005 InterruptIn button1(PG_0); 00006 InterruptIn button2(PG_1); 00007 Serial pc(USBTX, USBRX); 00008 DigitalOut ledRED(PD_14); 00009 DigitalOut ledGreen(PB_0); 00010 DigitalOut ledBlue(PD_15); 00011 00012 TCS34725 colorSens(PB_9,PB_8); 00013 LoRaWAN OCTA_LoRa(PC_12, PD_2); 00014 00015 double delay = 0.5; // 500 ms 00016 uint16_t r,g,b,c; 00017 00018 void BTN1pressed() 00019 { 00020 delay = 0.1; // 100 ms 00021 00022 } 00023 00024 void BTN1released() 00025 { 00026 delay = 0.5; // 500 ms 00027 } 00028 00029 void BTN2pressed() 00030 { 00031 //Andere code nodig 00032 00033 } 00034 00035 void BTN2released() 00036 { 00037 char data[50]; 00038 char msg[25]= "AT+SENDB="; 00039 sprintf(msg+9, "%04X", r); 00040 sprintf(msg+13, "%04X", g); 00041 sprintf(msg+17, "%04X", b); 00042 sprintf(msg+21, "%04X", c); 00043 bool ok = OCTA_LoRa.sendMessage(msg); 00044 OCTA_LoRa.recieveData(data, 19); // Read data 00045 wait(0.2); 00046 pc.printf("Received:%s \r\n", data); 00047 00048 } 00049 00050 int main() 00051 { 00052 00053 //char data[202]; 00054 00055 // Assign functions to button1 00056 button1.fall(&BTN1pressed); 00057 button1.rise(&BTN1released); 00058 00059 // Assign functions to button2 00060 button2.fall(&BTN2pressed); 00061 button2.rise(&BTN2released); 00062 00063 //Turn off RGB led 00064 ledRED = 1; 00065 ledGreen = 1; 00066 ledBlue = 1; 00067 00068 //serial communication 00069 pc.baud(115200); 00070 pc.printf("Welcome at University of Antwerp #STEM2020 \r\n"); 00071 00072 //initialization of the color sensor 00073 if(!colorSens.init(0xD5, 0x03)){ 00074 pc.printf("ERROR: SENSOR\r\n"); //check to see if i2c is responding 00075 } 00076 //initialization of the LoRaWAN module 00077 if(!OCTA_LoRa.init()){ 00078 pc.printf("ERROR: LoRaWAN module\r\n"); 00079 } 00080 00081 00082 while (1) { 00083 colorSens.getColor(r,g,b,c); //pass variables by reference... 00084 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 00085 ledRED = !ledRED; //Toggle LED 00086 wait(delay); 00087 } 00088 }
Generated on Wed Jul 20 2022 02:38:12 by
1.7.2