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: LoRaMacLib SX1276Lib mbed Chainable_RGB_LED DigitDisplay
Fork of LoRaWAN by
Revision 7:063ff5895cfe, committed 2015-10-21
- Comitter:
- Alliance
- Date:
- Wed Oct 21 11:20:58 2015 +0000
- Parent:
- 6:ea71f564e0ce
- Child:
- 8:d3a75f9efef8
- Commit message:
- _-
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Wed Oct 21 06:35:37 2015 +0000
+++ b/main.cpp Wed Oct 21 11:20:58 2015 +0000
@@ -95,7 +95,7 @@
/*!
* User application data buffer size
*/
-#define APP_DATA_SIZE 8
+#define APP_DATA_SIZE 5
/*!
* User application data
@@ -129,6 +129,9 @@
static LoRaMacEvent_t LoRaMacEvents;
+static float LightValue = 0.0;
+static uint8_t LightMode = 0; // 0:automatic, 1:manual
+
Ticker Led1Timer;
Ticker Led2Timer;
Ticker BuzTimer;
@@ -136,11 +139,9 @@
#define NUM_LED 3
-// ChainableLED(clk, data, number_of_leds)
+AnalogIn LightSens( A1 );
ChainableLED color_led(D6, D7, NUM_LED);
-
DigitDisplay display(D8, D9);
-
DigitalOut buzzer(A2);
@@ -155,19 +156,20 @@
*/
static void PrepareTxFrame( uint8_t port )
{
- AppData[0] = 0x99;
- AppData[1] = 0x99;
- AppData[2] = 0x99;
- AppData[3] = 0x99;
- AppData[4] = 0x99;
- AppData[5] = 0x99;
- AppData[6] = 0x99;
- AppData[7] = 0x99;
+ uint32_t tempValue = (uint32_t)(LightValue*1000000.0);
+
+ debug( "[Tx] LightValue=%d 0x%x\n\r" , tempValue, tempValue);
+
+ AppData[0] = LightMode;
+ AppData[1] = ((tempValue&0xFF000000)>>24)&0xFF;
+ AppData[2] = ((tempValue&0x00FF0000)>>16)&0xFF;
+ AppData[3] = ((tempValue&0x0000FF00)>>8)&0xFF;
+ AppData[4] = (tempValue&0x000000FF);
}
static void ProcessRxFrame( LoRaMacEventFlags_t *flags, LoRaMacEventInfo_t *info )
{
- debug( "RxDone \n\n\r" );
+ debug( "[Rx] Port=%d\n\r" , info->RxPort);
switch( info->RxPort ) // Check Rx port number
{
case 10:
@@ -178,7 +180,12 @@
break;
case 20:
- color_led.setColorRGB(0, info->RxBuffer[0], info->RxBuffer[1], info->RxBuffer[2] );
+ LightMode = info->RxBuffer[0];
+ debug( "[Rx] LightMode=%x - R G B= 0x%x 0x%x 0x%x\n\r" , LightMode, info->RxBuffer[1], info->RxBuffer[2], info->RxBuffer[3]);
+ if( LightMode )
+ {
+ color_led.setColorRGB(0, info->RxBuffer[1], info->RxBuffer[2], info->RxBuffer[3] );
+ }
break;
case 30:
@@ -268,8 +275,10 @@
uint8_t sendFrameStatus = 0;
#endif
bool trySendingFrameAgain = false;
-
- buzzer = 0;
+ float tempLightValue = 0;
+
+ LightMode = 0; // 0: manual, 1: automatic
+ buzzer = 0; // 0: OFF, 1: ON
debug( "\n\n\r LoRaWAN Class A Demo code \n\n\r" );
@@ -291,7 +300,7 @@
// NwkID = 0
// NwkAddr rand [0, 33554431]
DevAddr = randr( 0, 0x01FFFFFF );
-
+ debug( "- DevAddr = 0x%x\n\r" , DevAddr);
LoRaMacInitNwkIds( 0x000000, DevAddr, NwkSKey, AppSKey );
IsNetworkJoined = true;
#endif
@@ -359,6 +368,16 @@
trySendingFrameAgain = SendFrame( );
}
+ // Read light sensor
+ tempLightValue = LightSens.read( ) * 1.65;
+
+ LightValue = ( 1 - tempLightValue );
+
+ // Set automatic RGB from light sensor
+ if( LightMode == 0 )
+ {
+ color_led.setColorRGB( 0, ( uint8_t )( 255 * LightValue ), ( uint8_t )( 255 * LightValue ), ( uint8_t )( 255 * LightValue ) );
+ }
// TimerLowPowerHandler( );
}
}
