I don't think it will be easy (maybe not possible) to get your code to work in that way.
It will be much simpler if you use a "state machine" concept - which is a rather grand way of saying that you should use variables to keep track of what is happening.
I think your project has a series of states something like this
- waiting for a button press
- buttonA being held
- buttonA held long enough
- waiting for a button press
- buttonB being held
- buttonB held long enough
but when I write them down like that I suspect I don't really understand what you are trying to do.
Separately from that (while still consistent with it) this code is very unwieldy and repetitive
if (buttonR == HIGH && previusR == LOW && millis() - time > debounce)
{
time = millis();
if (state == HIGH)
state = LOW;
else
state = HIGH;
}
if (buttonB == HIGH && previousB == LOW && millis() - time > debounce)
{
time = millis();
if (state == HIGH)
state = LOW;
else
state = HIGH;
}
For a start, both tests give the same result so it is hard to see the purpose of the tests
Then, both tests depend on the same time so it would make sense to deal with that first
if ( millis() - time > debounce ) {
if (buttonR == HIGH && previusR == LOW) {
}
if (buttonB == HIGH && previousB == LOW) {
}
}
...R