![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Workshop demo program
Dependencies: PinDetect mbed LoRaWAN-lib SX1272Lib
Diff: app/app.cpp
- Revision:
- 15:07f7e9ce7e21
- Parent:
- 14:7d092ebf7250
- Child:
- 16:4667c0c0b48b
--- a/app/app.cpp Fri Apr 28 21:10:39 2017 +0000 +++ b/app/app.cpp Tue May 02 13:30:48 2017 +0000 @@ -69,6 +69,7 @@ //check if button was just pressed checkButton(); + } void checkButton(void){ @@ -86,7 +87,7 @@ void checkAlarm(void){ uint16_t position = rotary.read_u16(); //check if should trigger alarm - if(position / BYTE_TO_PERCENT > ALARM_THRESHOLD){ + if(position / BYTE_TO_PERCENT > (ALARM_THRESHOLD + 1)){ //if the alarm has not already been triggered if(!alarmThresholdTriggered){ alarmThresholdTriggered = true;//set the alarm to triggered @@ -94,8 +95,13 @@ transmitData(position);//transmit data } } - else if(alarmThresholdTriggered){ - alarmThresholdTriggered = false; + else if(position / BYTE_TO_PERCENT < (ALARM_THRESHOLD - 1)){ + if(alarmThresholdTriggered){ + //alarm just changed state to not triggered + flashLED(BLINK_COUNT_EVENT_TRANSMIT); + transmitData(position);//transmit data + alarmThresholdTriggered = false; + } } } @@ -109,7 +115,7 @@ //Transmit rotory position and alarm status void transmitData(uint16_t position){ addRotaryData(position); //add the rotary position to data - + setDataToSend(data, dataLength); //set data to be transmitted sendLoraTransmission(); //queue transmission dataLength = 0; //reset data length so new data starts back at begining @@ -131,7 +137,7 @@ data[dataLength++] = ALARM_DATA_CHANNEL; data[dataLength++] = ALARM_DATA_TYPE; - data[dataLength++] = (uint8_t)position >= ALARM_THRESHOLD; //add binary for it allar triggered or not + data[dataLength++] = (uint8_t)position >= ALARM_THRESHOLD; //add binary for it alarm triggered or not } //start flash LED @@ -140,6 +146,10 @@ TimerStart(&ledTimer); //start timer to toggle LED state } flashCount += times; //set the number of times to flash + //make sure it is not set to high + if(flashCount > 10){ + flashCount = 10; + } led.write(1); //turn on LED }