 
 #define PIN_RX     1 // Serial
 #define PIN_TX     2 // Serial
-#define PIN_LED_R  3 // LED
-#define PIN_D4     4 //
+#define PIN_LED_G  3 // LED
+#define PIN_D4     4 // Button
 #define PIN_DHT    5 // Hum and Temp Sensor
-#define PIN_D6     6 //
-#define PIN_D7     7 //
-#define PIN_D8     8 //
-#define PIN_LED_G  9 // LED
-#define PIN_LED_B 10 // LED
+#define PIN_D6     6 // Button
+#define PIN_D7     7 // Button
+#define PIN_D8     8 // Button
+#define PIN_LED_B  9 // LED
+#define PIN_LED_R 10 // LED
 #define PIN_MOSI  11 // Programming
 #define PIN_MISO  12 // Programming
 #define PIN_SCK   13 // Programming
 #define PIN_A1    A1 //
 #define PIN_A2    A2 //
-#define PIN_A3    A3 //
+#define PIN_LIGHT A3 // Light
 #define PIN_A4    A4 //
-#define PIN_A5    A5 // fff
+#define PIN_A5    A5 // 
 
-#define sampleDelay 1000
+#define SAMPLE_DELAY    1000
+#define BUTTON_DELAY     500
+#define AVERAGE_COUNTER  100
+#define NUM_BUTTONS        4
 
 dht          DHT;
 CmdMessenger cmdMessenger = CmdMessenger(Serial, ',', ';');
 uint32_t     lastSampleTime;
+uint32_t     lastButtonTime[NUM_BUTTONS];
 
 enum{
   kAcknowledge,

}

void OnSetRgb(){
  cmdMessenger.sendCmd(kAcknowledge);
}

void OnSetR(){
  uint16_t r = cmdMessenger.readInt16Arg();
  analogWrite(PIN_LED_R, r);
  cmdMessenger.sendCmd(kAcknowledge);
}

void OnSetG(){
  uint16_t g = cmdMessenger.readInt16Arg();
  analogWrite(PIN_LED_G, g);
  cmdMessenger.sendCmd(kAcknowledge);
}

void OnSetB(){
  uint16_t b = cmdMessenger.readInt16Arg();
  analogWrite(PIN_LED_B, b);
  cmdMessenger.sendCmd(kAcknowledge);
}

void checkSampleTime(){
  if( (millis() - lastSampleTime) > sampleDelay){
    wdt_reset();
    DHT.read22(PIN_DHT);  
    wdt_reset();
    lastSampleTime = millis();
  }
}

void OnGetTemp(){
  checkSampleTime();
  cmdMessenger.sendCmd(kAcknowledge, DHT.temperature);
}

void OnGetHumidity(){
  checkSampleTime();
  cmdMessenger.sendCmd(kAcknowledge, DHT.humidity);
}

void setup() {

  kSetB,
  kGetTemp,
  kGetHumidity,
  kGetLight,
  kTemp,
  kHumidity,
  kLight,
  kButtonPressed,
};

void attachCommandCallbacks(){
  cmdMessenger.attach(              OnUnknownCommand);
  cmdMessenger.attach(kSetRgb,      OnSetRgb        );
  cmdMessenger.attach(kSetR,        OnSetR          );
  cmdMessenger.attach(kSetG,        OnSetG          );
  cmdMessenger.attach(kSetB,        OnSetB          );
  cmdMessenger.attach(kGetTemp,     OnGetTemp       );
  cmdMessenger.attach(kGetHumidity, OnGetHumidity   );
  cmdMessenger.attach(kGetLight,    OnGetLight      );
}

void OnUnknownCommand(){
