 #include <avr/wdt.h>
 #include <avr/pgmspace.h>
 
-/*******Interrupt-based Rotary Encoder Sketch*******
-by Simon Merrett, based on insight from Oleg Mazurov, Nick Gammon, rt, Steve Spence
-http://www.instructables.com/files/orig/FSD/13QB/IM3QGLHR/FSD13QBIM3QGLHR.ino */
+/*#include <Adafruit_NeoPixel.h>
+#ifdef __AVR__
+  #include <avr/power.h>
+#endif*/
+
+/* Encoder Library, for measuring quadrature encoded signals
+ * http://www.pjrc.com/teensy/td_libs_Encoder.html
+ * Copyright (c) 2011,2013 PJRC.COM, LLC - Paul Stoffregen <paul@pjrc.com>
+ *
+ * Version 1.2 - fix -2 bug in C-only code
+ * Version 1.1 - expand to support boards with up to 60 interrupts
+ * Version 1.0 - initial release
+ */
 
 /*******Watchdog timer by http://donalmorrissey.blogspot.co.uk/2010/04/sleeping-arduino-part-5-wake-up-via.html *********/
 
 /*******LCD5110_Library to control the lcd http://www.rinkydinkelectronics.com/library.php?id=48 *******/
 
-Encoder rotEncoder(2, 3);
-U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);
-
-//static int pinA = 2;                  // Our first hardware interrupt pin is digital pin 2
-//static int pinB = 3;                  // Our second hardware interrupt pin is digital pin 3
-//volatile byte aFlag = 0;              // let's us know when we're expecting a rising edge on pinA to signal that the encoder has arrived at a detent
-//volatile byte bFlag = 0;              // let's us know when we're expecting a rising edge on pinB to signal that the encoder has arrived at a detent (opposite direction to when aFlag is set)
-//volatile byte encoderPos = 0;         // This variable stores our current value of encoder position. Change to int or uin16_t instead of byte if you want to record a larger range than 0-255
-//volatile byte oldEncPos = 0;          // Stores the last encoder position value so we can compare to the current reading and see if it has changed (so we know when to print to the serial monitor)
-volatile byte reading = 0;            // Somewhere to store the direct values we read from our interrupt pins before checking to see if we have moved a whole detent
-LCD5110 myGLCD(12,11,10,8,9);  //
-extern unsigned char SmallFont[];
-extern unsigned char TinyFont[];
-extern unsigned char MediumNumbers[];
-volatile int f_wdt=1;                 // Sleep arduino
-
-long posit = 0;
-
-// pins for the LEDs:
-
-const int analogInPinV = A0;            // Analog input pin that the potentiometer is attached to / Default = A5
-const int analogInPinA = A1; 
-//const int buttonA = 2;                 // User Buttons from the rotary encoder
-//const int buttonB = 3;
-const int buttonC = 4;
-
-char selection = 0;                    // Choose true for PWM, false for no PWM
-const int  overchargeIndicatorLed = 5; // LedOutput  Default = 2
-
-
-/* Global Declaration */
+/*******U8glib.h C++ Interface Universal 8bit Graphics Library Copyright (c) 2011, olikraus@gmail.com***/
+
+/*******DECLARATIONS*******/
+/*#define LED_PIN            7
+
+Adafruit_NeoPixel LED_RGB = Adafruit_NeoPixel(1, LED_PIN, NEO_GRB + NEO_KHZ800);*/
+
+Encoder rotEncoder(2, 3);                                         // Rotary encoder object declaration
+
+U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE|U8G_I2C_OPT_DEV_0);    // OLED display declaration
+
+LCD5110 myGLCD(12,11,10,8,9);                                     // LCD display declaration
+
+volatile int f_wdt=1;                                             // Sleep arduino
+
+long posit = 0;                                                   // This value will be the previous value of the position of the rotary encoder
+
+const int analogInPinV = A0;                 // Analog input pin that the potentiometer (Voltmeter) is attached to / Default = A0
+const int analogInPinA = A1;                 // Analog input pin that the potentiometer (Ammeter) is attached to / Default = A1
+const int buttonC = 4;                       // Digital input pin that the button of the rotary encoder is attached to / Default = 4
+
+char selection = 0;                          // Choose true for PWM, false for no PWM
+const int  overchargeIndicatorLed = 5;       // LedOutput  Default = 2
 
 float VinMax;                                // Maximum Input Voltage Default = 4
 unsigned int R1;                             // Bottom resistance Kohm Default = 10

float hysteresis ;                           // Value of the hysteresis
float setpointHigh = (VinMax + hysteresis);  // Set setpointHigh Caution the battery may go beyond the overcharge
float setpointLow = (VinMax - hysteresis) ;  // Set setpointLow
unsigned int times;
unsigned char cpt =0;
bool stateLCD =0;

int limitOverchargeInAnalog;                 // Limit of the overcharge in analog value
int limitSetpointHighInAnalog;               // Limit of the setpointhigh in analog value

///////FUNCTION/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

void displaySerialInformation()                                                              // Read the global declaration in order to display information on the serial monitor // 0 for all value
{        
  int k;  
  char myChar;                                                     
  int len = strlen_P(serialDisplayVoltage);
  for (k = 0; k < len; k++)
  {
