 unsigned char intensity;                     // Used to set the intensity of the led with PWM control
 char pourcentageIntensity;
 int intensityInPercent;
-bool oldValue = 0;
+unsigned char curveCpt = 0;
+float curveTab[120] ;
 byte xCurve = 0;
-int arrayVin[83];
 
 const char serialDisplayVoltage[] PROGMEM  = {"Actual Voltage : "};
-int k;
-char myChar;
 char state = 0;
 bool testFirstSleep = HIGH;
 bool testCase5 = LOW;
 
-/* Value read from the pot */
+/* Value read from the potentiometers */
 int sensorValue = 0;       
-int ampvalue = 0;
+//int ampvalue = 0;
 
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 ///////////SETUP//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 
 void setup() {
+  char i = 0;
   // put your setup code here, to run once:
   // initialize serial:
   Serial.begin(9600);
                                            
-  pinMode(2, INPUT_PULLUP);             // Set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
-  pinMode(3, INPUT_PULLUP);             // Set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
-  //attachInterrupt(0,2,RISING);          // Set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
-  //attachInterrupt(1,3,RISING);          // Set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
-  pinMode(overchargeIndicatorLed, OUTPUT); // Set the LED indicator in OUTPUT mode
-  pinMode(13, OUTPUT);                     // Set the pin 13 as an output
-  digitalWrite(13,HIGH);                   // Set the pin 13 to HIGH (that turns on the display's blue light so we can see something)
-  //pinMode(buttonA, INPUT_PULLUP);          // Initialize the user buttons
-  //pinMode(buttonB, INPUT_PULLUP);
-  pinMode(buttonC, INPUT_PULLUP);
-  
-  initEEPROMValue();                       // initialization of VinMax, maxControllerVoltage, R1, R2, hysteresis and times with the last values stored in the EEPROM
-  initLCD(500);                            // Setup the WDT
-  
-  MCUSR &= ~(1<<WDRF);                     // Clear the reset flag
-  
-  /* In order to change WDE or the prescaler, we need to
-  * set WDCE (This will allow updates for 4 clock cycles).
-  */
-  WDTCSR |= (1<<WDCE) | (1<<WDE);
-  
-  /* set new watchdog timeout prescaler value */
-  WDTCSR = 1<<WDP0 | 1<<WDP1; /* 0.125 seconds */
-  
-  /* Enable the WD interrupt (note no reset). */
-  WDTCSR |= _BV(WDIE);
-  
-  //Serial.println("Initialisation complete.");
-  delay(100); //Allow for serial print to complete.
+  pinMode(2, INPUT_PULLUP);                 // Set pinA as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
+  pinMode(3, INPUT_PULLUP);                 // Set pinB as an input, pulled HIGH to the logic voltage (5V or 3.3V for most cases)
+  //attachInterrupt(0,2,RISING);            // Set an interrupt on PinA, looking for a rising edge signal and executing the "PinA" Interrupt Service Routine (below)
+  //attachInterrupt(1,3,RISING);            // Set an interrupt on PinB, looking for a rising edge signal and executing the "PinB" Interrupt Service Routine (below)
+  pinMode(overchargeIndicatorLed, OUTPUT);  // Set the LED indicator in OUTPUT mode
+  pinMode(13, OUTPUT);                      // Set the pin 13 as an output
+  digitalWrite(13,HIGH);                    // Set the pin 13 to HIGH (that turns on the display's blue light so we can see something)
+  pinMode(buttonC, INPUT_PULLUP);           // Initialize the encoder button
+  
+  initEEPROMValue();                        // initialization of VinMax, maxControllerVoltage, R1, R2, hysteresis and times with the last values stored in the EEPROM
+  initOLED(500);                             // Setup the WDT
+  
+  MCUSR &= ~(1<<WDRF);                      // Clear the reset flag  
+  WDTCSR |= (1<<WDCE) | (1<<WDE);           // In order to change WDE or the prescaler, we need to set WDCE (This will allow updates for 4 clock cycles).
+  WDTCSR = 1<<WDP0 | 1<<WDP1;               // Set new watchdog timeout prescaler value (0.125 seconds)
+  WDTCSR |= _BV(WDIE);                      // Enable the WD interrupt (note no reset)
+  for (i = 0; i<120; i++)
+    {
+      curveTab[i]= 0;
+    }
+
+  delay(100);                               //Allow for serial print to complete.
 }
 
 

}


void initLCD( int tempo )                         // Initialize the LCD
{  
  u8g.begin();
  if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {

//    ampvalue = analogRead(analogInPinA);
//    Serial.println("current:");
//    Serial.println(ampvalue);
    configureSelection();           // Changes the value of "selection" depending on the position of the encoder
    seriesRegulator();              // Write 0 in the parenthesis for no PWM or 1 for the PWM //default selection
    displayOLED(selection);         // Default selection
    displaySerialInformation();     // Read the global declaration in order to display information on the serial monitor

    Serial.println("curveCpt");
    Serial.println(curveCpt);
    
    enableMenu(testButtonC());      // Displays the menu if you press the rotary encoder // You can change Vlim, Vmax, R1, R2, hysteresis, times and decide if you the arduino to sleep depending on the position of the encoder
    f_wdt = 0;

    enterSleepArduino();            // Re-enter sleep mode
  }
  else
  {
