 
 // Checks all the buttons.
 void buttonsCheck() {
-	if (right.check() == LOW) {
-		menu_system.next_screen();
-	}
-	if (left.check() == LOW) {
-		menu_system.previous_screen();
-	}
-	if (up.check() == LOW) {
-		menu_system.call_function(increase);
-	}
-	if (down.check() == LOW) {
-		menu_system.call_function(decrease);
-	}
-	if (enter.check() == LOW) {
-		menu_system.switch_focus();
-	}
+  if (right.check() == LOW) {
+    menu_system.next_screen();
+  }
+  if (left.check() == LOW) {
+    menu_system.previous_screen();
+  }
+  if (up.check() == LOW) {
+    menu_system.call_function(increase);
+  }
+  if (down.check() == LOW) {
+    menu_system.call_function(decrease);
+  }
+  if (enter.check() == LOW) {
+    menu_system.switch_focus();
+  }
 }
 
 // Callback function that will be attached to back_line.
 void go_back() {
-	// This function takes reference to the wanted menu.
-	menu_system.change_menu(main_menu);
+  // This function takes reference to the wanted menu.
+  menu_system.change_menu(main_menu);
 }
 
 void goto_outputs_menu() {
-	menu_system.change_menu(outputs_menu);
+  menu_system.change_menu(outputs_menu);
 }
 
 void goto_inputs_menu() {
-	menu_system.change_menu(inputs_menu);
-}
-
-void increase_pin9() {
-	if (pin9_level < 10) {
-		pin9_level++;
-	} else {
-		pin9_level = 0;
-	}
-	PWM_log(pin9, pin9_level);
-	saved_text = (char*)"  ";
-}
-
-void decrease_pin9() {
-	if (pin9_level > 0) {
-		pin9_level--;
-	} else {
-		pin9_level = 10;
-	}
-	PWM_log(pin9, pin9_level);
-	saved_text = (char*)"  ";
-}
-
-void increase_pin10() {
-	if (pin10_level < 10) {
-		pin10_level++;
-	} else {
-		pin10_level = 0;
-	}
-	PWM_log(pin10, pin10_level);
-	saved_text = (char*)"  ";
-}
-
-void decrease_pin10() {
-	if (pin10_level > 1) {
-		pin10_level--;
-	} else {
-		pin10_level = 10;
-	}
-	PWM_log(pin10, pin10_level);
-	saved_text = (char*)"  ";
-}
-
-void save_state() {
-	EEPROM.put(9, pin9_level);
-	EEPROM.put(10, pin10_level);
-	EEPROM.put(11, sample_period);
-	saved_text = (char*)" *";
+  menu_system.change_menu(inputs_menu);
+}
+
+void increase_pin6() {
+  if (pin6_level < 225) {
+    pin6_level += 25;
+  } else {
+    pin6_level = 250;
+  }
+  analogWrite(pin6, pin6_level);
+  output_saved = (char*)"  ";
+}
+
+void decrease_pin6() {
+  if (pin6_level > 25) {
+    pin6_level -= 25;
+  } else {
+    pin6_level = 0;
+  }
+  analogWrite(pin6, pin6_level);
+  output_saved = (char*)"  ";
+}
+
+void save_input() {
+  EEPROM.put(11, sample_period);
+  input_saved = (char*)" *";
+}
+
+void save_output() {
+  EEPROM.put(9, pin6_level);
+  output_saved = (char*)" *";
 }
 
 void increase_samplePeriod() {
-	if (sample_period < 10) {
-		sample_period++;
-	saved_text = (char*)"  ";
-	}
+  if (sample_period < 10) {
+    sample_period++;
+    input_saved = (char*)"  ";
+  }
 }
 
 void decrease_samplePeriod() {
-	if (sample_period > 0) {
-		sample_period--;
-	saved_text = (char*)"  ";
-	}
+  if (sample_period > 0) {
+    sample_period--;
+    input_saved = (char*)"  ";
+  }
 }
 
 void setup() {
-	Serial.begin(250000);
-
-	pinMode(pin9, OUTPUT);
-	pinMode(pin10, OUTPUT);
-
-    // Reads the values recorded in the EEPROM
-	EEPROM.get(9, pin9_level);
-	EEPROM.get(10, pin10_level);
-	EEPROM.get(11, sample_period);
-	PWM_log(pin9, pin9_level);
-	PWM_log(pin10, pin10_level);
-
-	lcd.begin(16, 2);
-
-	back_line.set_focusPosition(Position::LEFT);
-
-	back_line.attach_function(1, go_back);
-
-	outputs_line.attach_function(1, goto_outputs_menu);
-	outputs_line.attach_function(2, goto_outputs_menu);
-	inputs_line.attach_function(1, goto_inputs_menu);
-	inputs_line.attach_function(2, goto_inputs_menu);
-
-	pin9_line.attach_function(increase, increase_pin9);
-	pin9_line.attach_function(decrease, decrease_pin9);
-	pin10_line.attach_function(increase, increase_pin10);
-	pin10_line.attach_function(decrease, decrease_pin10);
-
-	oSave_line.attach_function(1, save_state);
-	iSample_line.attach_function(increase, increase_samplePeriod);
-	iSample_line.attach_function(decrease, decrease_samplePeriod);
-
-	menu_system.update();
+  Serial.begin(250000);
+
+  pinMode(pin6, OUTPUT);
+
+  // Reads the values recorded in the EEPROM
+  EEPROM.get(9, pin6_level);
+  EEPROM.get(11, sample_period);
+  analogWrite(pin6, pin6_level);
+
+  lcd.begin(16, 2);
+
+  back_line.set_focusPosition(Position::LEFT);
+
+  back_line.attach_function(1, go_back);
+  back_line.attach_function(2, go_back);
+
+  outputs_line.attach_function(1, goto_outputs_menu);
+  outputs_line.attach_function(2, goto_outputs_menu);
+  inputs_line.attach_function(1, goto_inputs_menu);
+  inputs_line.attach_function(2, goto_inputs_menu);
+
+  pin6_line.attach_function(increase, increase_pin6);
+  pin6_line.attach_function(decrease, decrease_pin6);
+
+  oSave_line.attach_function(1, save_output);
+  oSave_line.attach_function(2, save_output);
+  iSave_line.attach_function(1, save_input);
+  iSave_line.attach_function(2, save_input);
+  iSample_line.attach_function(increase, increase_samplePeriod);
+  iSample_line.attach_function(decrease, decrease_samplePeriod);
+
+  input_saved = (char*)" *";
+  output_saved = (char*)" *";
+
+  menu_system.update();
 }
 
 void loop() {
-	buttonsCheck();
-
-	static unsigned long lastMillis_sample = 0;
-	if (millis() - lastMillis_sample > (sample_period * 1000)) {
-		lastMillis_sample = millis();
-		pinA1_value = analogRead(pinA1);
-		pinA2_value = analogRead(pinA2);
-		menu_system.update();
-	}
-
-}
+  buttonsCheck();
+
+  static unsigned long lastMillis_sample = 0;
+  if (millis() - lastMillis_sample > (sample_period * 1000)) {
+    lastMillis_sample = millis();
+    pinA4_value = analogRead(pinA4);
+    pinA5_value = analogRead(pinA5);
+    menu_system.update();
+  }
+
+}

#include <LiquidCrystal.h>
#include <LiquidMenu.h>
#include <EEPROM.h>
#include "Button.h"

// An array holding linearized 8bit PWM values.
const uint8_t log_8bit[11] PROGMEM = {0, 1, 2, 3, 6, 12, 22, 40, 74, 138, 255};

// PWM function using the above array.
void PWM_log(uint8_t pin, uint8_t level) {
	analogWrite(pin, pgm_read_byte_near(log_8bit + level));
}

// Pin mapping for the display
const byte LCD_RS = 12;


// Button objects instantiation
const bool pullup = true;
Button left(A0, pullup);
Button right(7, pullup);
Button up(8, pullup);
Button down(9, pullup);
Button enter(10, pullup);

// Pin definitions and variables for their state.
const byte pin6 = 6;
byte pin6_level = 0;

const byte pinA4 = A4;
byte pinA4_value = 0;

const byte pinA5 = A5;
byte pinA5_value = 0;

// The analog reading sample period in seconds.
// It is later overwritten by it's EEPROM value.
unsigned short sample_period = 2;

// Text used for indication for the save lines.
char* input_saved;
char* output_saved;

enum FunctionTypes {
  increase = 1,
  decrease = 2,
};


// A LiquidLine object can be used more that once.
LiquidLine back_line(11, 1, "/BACK");


LiquidLine welcome_line1(1, 0, "LiquidMenu ", VERSION);
LiquidLine welcome_line2(1, 1, "System example");
LiquidScreen welcome_screen(welcome_line1, welcome_line2);

// These lines direct to other menus.
LiquidLine outputs_line(0, 0, "/Outputs");
LiquidLine inputs_line(0, 1, "/Inputs");
LiquidScreen io_screen(outputs_line, inputs_line);

// This is the first menu.
LiquidMenu main_menu(lcd, welcome_screen, io_screen, 1);


LiquidLine pin6_line(0, 0, "Pin 6: ", pin6_level);
LiquidScreen pin6_screen(pin6_line);

LiquidLine oSave_line(0, 0, "Save", output_saved);
LiquidScreen oSecondary_screen(oSave_line, back_line);

// This is the second menu.
LiquidMenu outputs_menu(lcd, pin6_screen, oSecondary_screen);


LiquidLine pinA4_line(0, 0, "Pin A4: ", pinA4_value);
LiquidLine pinA5_line(0, 1, "Pin A5: ", pinA5_value);
LiquidScreen pinsA4_A5_screen(pinA4_line, pinA5_line);

LiquidLine iSample_line(0, 0, "Sample: ", sample_period, "s");
LiquidLine iSave_line(0, 1, "Save", input_saved);
LiquidScreen iSecondary_screen(iSample_line, iSave_line, back_line);

// And this is the final third menu.
LiquidMenu inputs_menu(lcd, pinsA4_A5_screen, iSecondary_screen);

/*
 * LiquidSystem object combines the LiquidMenu objects to form
