#include <LiquidCrystal_I2C.h>
#define LCD_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_ROWS 2
#define POT A0
#define MIN_POT 0
#define MAX_POT 1023
#define LEFT_STOP -150 // in GRAD -360
#define RIGHT_STOP 190 // in GRAD
#define GRAD_SIGN 223 // °
LiquidCrystal_I2C lcd(LCD_ADDR, LCD_COLUMNS, LCD_ROWS);
const unsigned long interval_lcd = 50;
int interval_green;
char buffer_0 [15];
char buffer_1 [15];
int potValue, pos, grad;
void setup() {
pinMode(POT, INPUT);
lcd.begin(16,2);
lcd.init();
lcd.backlight();
}
void loop() {
static unsigned long previousMillis_lcd = 0;
unsigned long currentMillis = millis();
potValue = analogRead(POT);
pos = map(potValue,MIN_POT,MAX_POT,LEFT_STOP,RIGHT_STOP);
if (pos < 0){
grad = pos + 360;
}
else{
grad = pos;
}
if (currentMillis - previousMillis_lcd >= interval_lcd) {
sprintf(buffer_0,"Ant%4d%1cPos%4d%1c",grad,char(GRAD_SIGN),pos,char(GRAD_SIGN));
lcd.setCursor(0,0);
lcd.print(buffer_0);
sprintf(buffer_1,"PotVal %9d",potValue);
lcd.setCursor(0,1);
lcd.print(buffer_1);
previousMillis_lcd = currentMillis;
}
}