Created
March 31, 2014 02:00
-
-
Save murilopontes/9883746 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <AIR430BoostFCC.h> | |
// ----------------------------------------------------------------------------- | |
/** | |
* Defines, enumerations, and structure definitions | |
*/ | |
#define ADDRESS_LOCAL 0x01 | |
/** | |
* sPacket - packet format. | |
*/ | |
struct sPacket | |
{ | |
uint8_t from; // Local node address that message originated from | |
uint8_t message[59]; // Local node message [MAX. 59 bytes] | |
}; | |
// ----------------------------------------------------------------------------- | |
/** | |
* Global data | |
*/ | |
struct sPacket rxPacket; | |
// ----------------------------------------------------------------------------- | |
// Main example | |
void setup() | |
{ | |
// The radio library uses the SPI library internally, this call initializes | |
// SPI/CSn and GDO0 lines. Also setup initial address, channel, and TX power. | |
Radio.begin(ADDRESS_LOCAL, CHANNEL_1, POWER_MAX); | |
rxPacket.from = 0; | |
memset(rxPacket.message, 0, sizeof(rxPacket.message)); | |
// Setup serial for debug printing. | |
Serial.begin(115200); | |
/** | |
* Setup LED for example demonstration purposes. | |
* | |
* Note: Set radio first to ensure that GDO2 line isn't being driven by the | |
* MCU as it is an output from the radio. | |
*/ | |
pinMode(RED_LED, OUTPUT); // Use red LED to display message reception | |
digitalWrite(RED_LED, LOW); | |
pinMode(BLUE_LED, OUTPUT); | |
} | |
int blink=0; | |
void loop() | |
{ | |
// Turn on the receiver and listen for incoming data. Timeout after 1 seconds. | |
// The receiverOn() method returns the number of bytes copied to rxData. | |
if (Radio.receiverOn((unsigned char*)&rxPacket, sizeof(rxPacket), 1000) > 0) | |
{ | |
digitalWrite(RED_LED, HIGH); | |
Serial.print("FROM: "); | |
Serial.print(rxPacket.from); | |
Serial.print(" MSG: "); | |
Serial.println((char*)rxPacket.message); | |
digitalWrite(RED_LED, LOW); | |
} | |
else { | |
Serial.println("RX Timeout"); | |
blink++; | |
if(blink%2) analogWrite(BLUE_LED,10); | |
else analogWrite(BLUE_LED,1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment