so stuck with this so I'm using the click encoder library in a power supply project with one rotary encoder so my problem is that wen I try to adjust current after I set the voltage the current value starts were voltage left off so say I set voltage to 0.5 then I go to current I turn the rotary encoder and it goes from 0.00 to 0.6 I know why this is happening but I cant think of a way to reset "value" apon entering the set current, set voltage screens respectively ill try to post relevant code as this project is sort of lengthy
void readEnc() {
value+=encoder->getValue();
if(value < 0) {
value = 0;
}
if(value > last) {
last = value;
up = true;
delay(100);
} else if(value < last) {
last = value;
down = true;
delay(100);
}
if(value == last) {
turn = true;
} else {
turn = false;
}
}
void menuLogic() {
if(turn) {
delay(150);
switch(screen) {
case 0:
switch(cursorPos) {
case 0:
if(up) {
screen0();
lcd.setCursor(7,1);
lcd.write((uint8_t)0);
cursorPos = 1;
}
break;
case 1:
if(down) {
screen0();
lcd.setCursor(7,2);
lcd.write((uint8_t)0);
cursorPos = 0;
}
break;
}
break;
case 1:
switch(cursorPos) {
case 1:
if(up) {
screen1();
lcd.setCursor(15,3);
lcd.write((uint8_t)0);
cursorPos = 2;
}
}
if(up) {
voltage = value;
voltage = voltage * 0.1;
if(voltage > 20) {
voltage = 20;
}
lcd.setCursor(7,0);
lcd.print(voltage,3);
lcd.print("V");
lcd.write(1);
lcd.print(" ");
} else if(down) {
voltage = value;
voltage = voltage *0.1;
if(voltage < 0) {
voltage = 0;
}
lcd.setCursor(7,0);
lcd.print(voltage,3);
lcd.print("V");
lcd.write(1);
lcd.print(" ");
}
break;
case 2:
if(up) {
current = value;
current = current * 0.1;
if(current > 3) {
current = 3;
}
lcd.setCursor(6,0);
lcd.print(current,3);
lcd.print("A");
lcd.write(1);
lcd.print(" ");
} else if(down) {
current = value;
current = current * 0.1;
if(current < 0) {
current = 0;
}
lcd.setCursor(6,0);
lcd.print(current,3);
lcd.print("A");
lcd.write(1);
lcd.print(" ");
}
}
down = false;
up = false;
turn = false;
}
}
power_supply_project20x4.ino (9.79 KB)