     }
   }
 }
+
+
+void updateButtons() {
+  // updates each button status and sees if it changed.
+  // add more or less code according to suit your buttons.
+  // 
+  debouncer3.update();
+  if(debouncer3.fell()) {
+    buttons_0_6 |= 0b00000001;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer3.rose()) {
+    buttons_0_6 &= ~(0b00000001);
+    Serial1.write(buttons_0_6);
+  }
+  
+  debouncer4.update();
+  if(debouncer4.fell()) {
+    buttons_0_6 |= 0b00000010;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer4.rose()) {
+    buttons_0_6 &= ~(0b00000010);
+    Serial1.write(buttons_0_6);
+  }
+  
+  debouncer5.update();
+  if(debouncer5.fell()) {
+    buttons_0_6 |= 0b00000100;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer5.rose()) {
+    buttons_0_6 &= ~(0b00000100);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer6.update();
+  if(debouncer6.fell()) {
+    buttons_0_6 |= 0b00001000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer6.rose()) {
+    buttons_0_6 &= ~(0b00001000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer7.update();
+  if(debouncer7.fell()) {
+    buttons_0_6 |= 0b00010000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer7.rose()) {
+    buttons_0_6 &= ~(0b00010000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer8.update();
+  if(debouncer8.fell()) {
+    buttons_0_6 |= 0b00100000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer8.rose()) {
+    buttons_0_6 &= ~(0b00100000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer9.update();
+  if(debouncer9.fell()) {
+    buttons_0_6 |= 0b01000000;
+    Serial1.write(buttons_0_6);
+  } else if(debouncer9.rose()) {
+    buttons_0_6 &= ~(0b01000000);
+    Serial1.write(buttons_0_6);
+  }
+
+  debouncer10.update();
+  if(debouncer10.fell()) {
+    buttons_7_13 |= 0b00000001;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer10.rose()) {
+    buttons_7_13 &= ~(0b00000001);
+    Serial1.write(buttons_7_13);
+  }
+
+  debouncer11.update();
+  if(debouncer11.fell()) {
+    buttons_7_13 |= 0b00000010;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer11.rose()) {
+    buttons_7_13 &= ~(0b00000010);
+    Serial1.write(buttons_7_13);
+  }
+
+  debouncer12.update();
+  if(debouncer12.fell()) {
+    buttons_7_13 |= 0b00000100;
+    Serial1.write(buttons_7_13);
+  } else if(debouncer12.rose()) {
+    buttons_7_13 &= ~(0b00000100);
+    Serial1.write(buttons_7_13);
+  }
+}
+
+
 
 void InitialiseIO(){
   pinMode(btStatus, INPUT);

  analogReadRes(12);
  analogReadAveraging(5);
  analogReference(INTERNAL);
}

void updateButtons() {
  debouncer3.update();
  if(debouncer3.fell()) {
    buttons_0_6 |= 0b00000001;
    Serial1.write(buttons_0_6);
  } else if(debouncer3.rose()) {
    buttons_0_6 &= ~(0b00000001);
    Serial1.write(buttons_0_6);
  }
  
  debouncer4.update();
  if(debouncer4.fell()) {
    buttons_0_6 |= 0b00000010;
    Serial1.write(buttons_0_6);
  } else if(debouncer4.rose()) {
    buttons_0_6 &= ~(0b00000010);
    Serial1.write(buttons_0_6);
  }
  
  debouncer5.update();
  if(debouncer5.fell()) {
    buttons_0_6 |= 0b00000100;
    Serial1.write(buttons_0_6);
  } else if(debouncer5.rose()) {
    buttons_0_6 &= ~(0b00000100);
    Serial1.write(buttons_0_6);
  }

  debouncer6.update();
  if(debouncer6.fell()) {
    buttons_0_6 |= 0b00001000;
    Serial1.write(buttons_0_6);
  } else if(debouncer6.rose()) {
    buttons_0_6 &= ~(0b00001000);
    Serial1.write(buttons_0_6);
  }

  debouncer7.update();
  if(debouncer7.fell()) {
    buttons_0_6 |= 0b00010000;
    Serial1.write(buttons_0_6);
  } else if(debouncer7.rose()) {
    buttons_0_6 &= ~(0b00010000);
    Serial1.write(buttons_0_6);
  }

  debouncer8.update();
  if(debouncer8.fell()) {
    buttons_0_6 |= 0b00100000;
    Serial1.write(buttons_0_6);
  } else if(debouncer8.rose()) {
    buttons_0_6 &= ~(0b00100000);
    Serial1.write(buttons_0_6);
  }

  debouncer9.update();
  if(debouncer9.fell()) {
    buttons_0_6 |= 0b01000000;
    Serial1.write(buttons_0_6);
  } else if(debouncer9.rose()) {
    buttons_0_6 &= ~(0b01000000);
    Serial1.write(buttons_0_6);
  }

  debouncer10.update();
  if(debouncer10.fell()) {
    buttons_7_13 |= 0b00000001;
    Serial1.write(buttons_7_13);
  } else if(debouncer10.rose()) {
    buttons_7_13 &= ~(0b00000001);
    Serial1.write(buttons_7_13);
  }

  debouncer11.update();
  if(debouncer11.fell()) {
    buttons_7_13 |= 0b00000010;
    Serial1.write(buttons_7_13);
  } else if(debouncer11.rose()) {
    buttons_7_13 &= ~(0b00000010);
    Serial1.write(buttons_7_13);
  }

  debouncer12.update();
  if(debouncer12.fell()) {
    buttons_7_13 |= 0b00000100;
    Serial1.write(buttons_7_13);
  } else if(debouncer12.rose()) {
    buttons_7_13 &= ~(0b00000100);
    Serial1.write(buttons_7_13);
  }
}


/* 
 *  Code to put on the Wheel (connected with Bluetooth to a another system)
   for wireless bluetooth button/shifter system using
   two Teensy 3.2 microcontrollers and 2 HC-05 bluetooth modules.

   Authors: Mika Takala & Juha Koljonen 2016

   PINOUT
   -------------------------------------------------------------------------
   0 serial rx
   1 serial tx
   2 bluetooth stat
   3-12 button inputs
   13  Teensy's own led
   14-20 unused
   21/A7 Battery_low_led
   22 Connection_led
   23 Battery voltage adc
   24-33 unused
   -------------------------------------------------------------------------

   NOTES ABOUT POWER SAVING MEASURES:
   -------------------------------------------------------------------------
   (1) 
   As the system is intended to be battery powered, the recommendation 
   is to program Teensy as USB TYPE = NO USB and use for example 24MHz 
   clock. These are set from Tools menu in Arduino/Teensyduino IDE:
   Setting NO USB will require you to press the manual program button on 
   Teensy to upload the code, but it will save a lot of power.

   (2)
   Additionally you can set all unused inputs as outputs, which
   makes them not floating and they will consume less power that way.
   This has been implemented with a macro, and it has NOT been enabled
   as default.
   PLEASE BE SURE TO NOT HAVE ANYTHING CONNECTED TO THE UNUSED PINS
   LISTED IN InitialiseIO() FUNCTION. THE AUTHOR(S) TAKE NOT RESPONSIBILITY
   IF YOU MANAGE TO FRY/SHORT OUT A PIN OR YOUR TEENSY MICROCONTROLLER.
   -------------------------------------------------------------------------
*/

// used pin definitions, other than buttons
#define btStatus 2
#define teensyLed 13
#define batteryLed 21 
