/////////////////////////ENCODER////////////////////
#include <Encoder.h>
Encoder myEnc(2, 3);
long position = -999;
/////////////////////////LCD////////////////////////
#include <LiquidCrystal_I2C.h>
#define I2C_ADDR 0x27
#define LCD_COLUMNS 16
#define LCD_LINES 2
LiquidCrystal_I2C lcd(I2C_ADDR, LCD_COLUMNS, LCD_LINES);
int ACT = 0;
int SBY = 0;
int STR = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("ACT");
lcd.setCursor(0,1);
lcd.print("SBY");
lcd.setCursor(5, 0);
lcd.print(ACT);
lcd.setCursor(5,1);
lcd.print(SBY);
pinMode(4, INPUT);
}
int lastClk = HIGH;
void loop() {
// put your main code here, to run repeatedly:
//-------------------ENCODER ROTATION----------------------------
long newPos = myEnc.read();
if (newPos != position)
{
if (newPos < position)
{
SBY--;
}
else if (newPos > position)
{
SBY++;
}
position = newPos;
Serial.println(newPos);
Serial.print("SBY = ");
Serial.println(SBY);
}
//-------------------ENCODER BUTTON----------------------------
//if (digitalRead(ENCODER_BTN) == LOW) {
//digitalWrite(LED_BUILTIN, HIGH);
//} else {
//digitalWrite(LED_BUILTIN, LOW);
// }
//-------------------LCD PRINTING----------------------------
lcd.setCursor(5, 0);
lcd.print(ACT);
lcd.setCursor(5,1);
lcd.print(SBY);
//-------------------ERASE OVERFLOW NUMBERS---------------
lcd.setCursor(8,0);
lcd.print(" ");
lcd.setCursor(8,1);
lcd.print(" ");
//-------------------READ SWITCH BUTTON----------------------------
int stateButton = digitalRead(4); //read the state of the button
//-------------------SWAP SBY TO ACTIVE IF BUTTON PRESSED ----------
// if(stateButton == 1){
// STR=ACT;
// ACT=SBY;
// SBY=STR;
// }
}