#define SET0(REG,BIT) REG &= ~(1<<BIT)
#define SET1(REG,BIT) REG |= (1<<BIT)
#define TEST(REG,BIT) (REG&(1<<BIT))




#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27 ,20, 4);

void setup() {

  lcd.init();
  lcd.backlight();

Serial.begin(9600);

   SET0(ADMUX,REFS1); // voľba Aref
   SET0(ADMUX,REFS0);
   SET1(ADMUX,ADLAR); // zarovnanie nahor
   SET1(ADMUX,MUX0); // voľba kanála ADC1
   SET0(ADMUX,MUX1);
   SET0(ADMUX,MUX2);
   SET0(ADMUX,MUX3);
   SET1(ADCSRA,ADEN); // zapnutie ADC
   SET0(ADCSRA,ADATE); // spúšťanie príkazom
   SET0(ADCSRA,ADIE); // negenerovanie prerušenia
   SET1(ADCSRA,ADPS2); // voľba preddeličky 128 
   SET1(ADCSRA,ADPS1);
   SET1(ADCSRA,ADPS0);


}

void loop() {
   SET1(ADCSRA,ADSC);

   int x = ADCH;
   x = map(ADCH,0 , 255 , 0,1023);

   while( TEST(ADCSRA,ADIF)==0 ){

   lcd.setCursor(0, 0);
   lcd.println(ADCH);
   delay(10);
   lcd.setCursor(0, 1);
   lcd.println(x);
   };
   lcd.println(x);

   Serial.println(x);
}