I've used this method before in my code in order to detect the switch from HIGH to LOW in my button, but now it doesn't work. I've tried multiple things included adding resistors, making it INPUT_PULLUP, and changing the code around.
Whenever the button is LOW, v_press should be 0. Whenever it is HIGH, it should set it to 1 and wait for it to turn LOW before it sets it to 0 again. However, when I press the button it somehow triggers the last code of "digitalRead(variable) == LOW && v_press == 1" in every "if statement", making it true, setting it back to 0, and repeating the process over again, endlessly cycling the "if" blocks entirely.
How can I fix this? May someone please look over my code?
void loop(){
//Cycle Chars
if (digitalRead(v_cycle) == HIGH && (v_mode == 0 || v_mode == 1) && v_press == 0)
{
v_press = 1;
v_abc += 1;
if (v_abc > 26)
{
v_abc = 1;
}
msg();
}
else if (digitalRead(v_cycle) == HIGH && v_mode == 2 && v_press == 0)
{
v_press = 1;
v_chr += 1;
if (v_chr > 18)
{
v_chr = 1;
}
msg();
}
else if (digitalRead(v_cycle) == LOW && v_press == 1);
{
v_press = 0;
}
//Toggle Caps
if (digitalRead(v_caps) == HIGH && v_mode == 0 && v_press == 0)
{
v_press = 1;
v_mode = 1;
msg();
}
else if (digitalRead(v_caps) == HIGH && v_mode == 1 && v_press == 0)
{
v_press = 1;
v_mode = 0;
msg();
}
else if (digitalRead(v_caps) == LOW && v_press == 1)
{
v_press = 0;
}
//Cycle Mode
if (digitalRead(v_chars) == HIGH && v_press == 0)
{
v_press = 1;
v_mode ++;
if (v_mode > 2)
{
v_mode = 0;
}
msg();
}
else if (digitalRead(v_chars) == LOW && v_press == 1)
{
v_press = 0;
}
//Print Character
if (digitalRead(v_outp) == HIGH && v_mode == 0 && v_press == 0)
{
v_press = 1;
s_msg = s_msg + s_chr[0].substring(v_abc - 1, v_abc);
msg();
}
else if (digitalRead(v_outp) == HIGH && v_mode == 1 && v_press == 0)
{
v_press = 1;
s_msg = s_msg + s_chr[1].substring(v_abc - 1, v_abc);
msg();
}
else if (digitalRead(v_outp) == HIGH && v_mode == 2 && v_press == 0)
{
v_press = 1;
s_msg = s_msg + s_chr[2].substring(v_chr - 1, v_chr);
msg();
}
else if (digitalRead(v_outp) == LOW && v_press == 1)
{
v_press = 0;
}
}