   client.loop();
 
   // ir transmit loop
-  if(Serial.available()>0)
-     {
-        switch(Serial.read())
-        {
-          case '0': Serial.println("power"); rem2.necSend(0x3000, 0xfd02); break;
-          case '1': Serial.println("volume up"); rem2.necSend(0x3000, 0x7d82); break;
-          case '2': Serial.println("volume down"); rem2.necSend(0x3000, 0x7c83); break;
-          default: break;
-        }
-      
-     }
-  
+  if (Serial.available() > 0)
+  {
+    switch (Serial.read())
+    {
+      case '0': Serial.println("power"); rem2.necSend(0x3000, 0xfd02); break;
+      case '1': Serial.println("volume up"); rem2.necSend(0x3000, 0x7d82); break;
+      case '2': Serial.println("volume down"); rem2.necSend(0x3000, 0x7c83); break;
+      default: break;
+    }
+
+  }
+
+  // Encoder loop
+  if (bRTrig == true)
+  {
+    Serial.println("Int Rechts: ");
+    bRFlag = false;
+    bLFlag = false;
+    bRTrig = false;
+  }
+  if (bLTrig == true)
+  {
+    Serial.println("Int Links: ");
+    bRFlag = false;
+    bLFlag = false;
+    bLTrig = false;
+  }
+  // End Main Loop
 }
 
 void initWiFi() {
+  Serial.print("Attempting to connect to SSID: ");
+  Serial.println(ssid);
   if (strcmp (WiFi.SSID().c_str(), ssid) != 0) {
-   WiFi.begin(ssid, password);
-   WiFi.macAddress(mac);
- }
- while (WiFi.status() != WL_CONNECTED) {
-   delay(500);
- } 
+    Serial.println("Connecting...");
+    WiFi.begin(ssid, password);
+    WiFi.macAddress(mac);
+  }
+  while (WiFi.status() != WL_CONNECTED) {
+    Serial.print(".");
+    // wait 0.5 second for re-trying
+    delay(500);
+  }
+
+  Serial.print("Connected to ");
+  Serial.println(ssid);
 }
 
 void callback(char* topic, byte* payload, unsigned int length) {
- 
+
   Serial.print("Message arrived in topic: ");
   Serial.println(topic);
- 
+
   Serial.print("Message:");
   for (int i = 0; i < length; i++) {
     Serial.print((char)payload[i]);
   }
- 
+  display.clear();
+  display.setTextAlignment(TEXT_ALIGN_LEFT);
+  display.setFont(ArialMT_Plain_10);
+  display.drawString(0, 0, String((char *)payload));
+  display.display();
   Serial.println();
   Serial.println("-----------------------");
- 
+
 }
+
+void int_25() {
+  bRFlag = true;
+  if (bLFlag == true)
+  {
+    bRTrig = true;
+  }
+}
+
+void int_26() {
+  state = !state;
+  Serial.println("pressed!");
+}
+void int_2() {
+  bLFlag = true;
+  if (bRFlag == true)
+  {
+    bLTrig = true;
+  }
+}

void setup() {
  // put your setup code here, to run once:
  // Init Display
  display.init();
  display.flipScreenVertically();
  display.setFont(ArialMT_Plain_10);
  display.setTextAlignment(TEXT_ALIGN_LEFT);
  // Init WIFI
  initWiFi();
  // Init MQTT
  client.setServer(mqttServer, mqttPort);
  client.setCallback(callback);
  while (!client.connected()) {
     if (client.connect(mqttDeviceName + mac[3] + mac[4] + mac[5], mqttUser, mqttPassword )) {
     } else {
       delay(1000);
     }
  }
  client.subscribe("test");
  // Init Rotary
  encoder1.AddRotaryCounter(ROTARY_ID1, 10, -100, 100, 1, true );
  encoder1.SetRotary(ROTARY_ID1);
  encoder1.SetChanged(ROTARY_ID1); // This way we can force an update the first time through
  // Init IR
  rem1.begin(17,1);
  rem2.begin(16,1);
}

void loop() {

// Init MQTT
PubSubClient client(mqttServer, mqttPort, wifiClientSecure);
// Init Encoder
byte interruptPin1 = 25;
byte interruptPin2 = 26;
byte interruptPin3 = 36;
volatile byte state = LOW;

// Init IR
ESP32_RMT rem1, rem2;
