Hi everyone
I have a question that I do not know how to solve, it is very simple and I did not think it would not work
I want to create this counter and then with a switch function, make a program change in a block of 16 buttons that I already have programmed in a project
I want that when the counter reaches 6, it stops counting or, failing that, it continues to send 6, and the same when it reaches 0, to stop counting or to continue sending a 0
int octavas = 3;
int octavaUp = 2;
int octavaDown = 7;
int vbUp = 0;
int pvbUp = 0;
int vbDown = 0;
int pvbDown = 0;
unsigned long lastdebouncetime = 0;
unsigned long debouncedelay = 50;
void setup() {
Serial.begin(9600);
pinMode (octavaUp , INPUT_PULLUP);
pinMode (octavaDown , INPUT_PULLUP);
}
void loop()
{
vbUp = digitalRead(octavaUp);
vbDown = digitalRead(octavaDown);
if ((millis() - lastdebouncetime) > debouncedelay) {
if (vbUp != pvbUp) {
lastdebouncetime = millis();
if (vbUp == LOW) {
octavas++;
Serial.println(octavas);
if (octavas == 6)
{
octavas = 6;
}
} pvbUp = vbUp;
}
if (vbDown != pvbDown) {
lastdebouncetime = millis();
if (vbDown == LOW) {
octavas--;
Serial.println(octavas);
if (octavas == 0)
{
octavas = 0;
}
}
pvbDown = vbDown;
}
}
}
And how could I stop adding when it reaches 6 or stop subtracting when it reaches 0
or even if you keep pressing 0 and 6 are the minimum and maximum value