 #include <EEPROM.h>
 
 
-//RGB pins
-//Note: pins 5 and 6 use the fast, inaccurate PWM timer. If this becomes
-//an issue, look into software PWM implementations.
+// RGB pins
+// Note: pins 5 and 6 use the fast, inaccurate PWM timer. If this becomes
+// an issue, look into software PWM implementations.
 #define RED_PIN             3
 #define GREEN_PIN           5
 #define BLUE_PIN            6
 
-//Radio pins
-#define CE_PIN              9 //Radio chip enable pin
-#define CSN_PIN             10 //Radio chip select pin
-
-//Wireless protocol
-#define NODE_RF_ADDRESS         ((uint64_t)'SIGM!') //The 40-bit nRF address
-#define HEADER                  7446 //Must prefix every message
-#define BASE_STATION_ID         0x00 //The endpoint ID of the base station
+// Radio pins
+#define CE_PIN              9 // Radio chip enable pin
+#define CSN_PIN             10 // Radio chip select pin
+
+// Wireless protocol
+#define RF_ADDRESS(endpoint)         (0x5349474D00LL | (endpoint & 0xFF)) // Generates a 40-bit nRF address
+#define HEADER                  7446 // Must prefix every message
+#define BASE_STATION_ID         0x00 // The endpoint ID of the base station
+#define MULTICAST_ID            0xFF // The endpoint ID that all lights listen to
+
+#define ENDPOINT_PIPE           1 // The pipe for messages for this endpoint
+#define MULTICAST_PIPE          2 // The pipe for multicast messages
+
+#define CHANNEL                 80 // Channel center frequency = 2.4005 GHz + (Channel# * 1 MHz)
+#define NUM_RETRIES             5
 
 enum COMMANDS {
     CMD_SET_RGB       = 0x10,
-    CMD_BROADCAST_RGB = 0x11,
     CMD_PING          = 0x20,
     CMD_PING_RESPONSE = 0x21,
 };

typedef struct packet_tag {
    uint16_t header;
    uint8_t command;
    uint8_t endpoint;
    uint8_t rgb[3];
} packet_t;

//Serial protocol
#define MAX_SERIAL_LINE_LEN 20

//Firmware information
#define VERSION                 0 //The firmware version number
#define ENDPOINT_ID_LOCATION    0x000 //The address in EEPROM to store the ID


void networkRead(void);

unsigned long lastPingTime;

/**
 * Initialize radio and serial.
 */
void setup() {
    // Initialize the radio
    radio.begin();
    radio.setDataRate(RF24_250KBPS); // 250kbps should be plenty
    radio.setChannel(CHANNEL);
    radio.setPALevel(RF24_PA_MAX); // Range is important, not power consumption
    radio.setRetries(0, NUM_RETRIES);
    radio.setCRCLength(RF24_CRC_8); // Minimal error detection is fine
    radio.setPayloadSize(sizeof(packet_t));

    radio.openWritingPipe(RF_ADDRESS(BASE_STATION_ID));
    radio.openReadingPipe(ENDPOINT_PIPE, RF_ADDRESS(endpointID));
    radio.openReadingPipe(MULTICAST_PIPE, RF_ADDRESS(MULTICAST_ID));
    radio.setAutoAck(MULTICAST_PIPE, false); // Prevent ACK collisions on the multicast pipe
    radio.startListening();

    // Initialize serial console
