Using and or && within the keypad library

I am trying to figure out how to use && with in a custom "keyboard" using keypad.h
Basically if the state of the key is 1(aka active) it should be able to execute code then change the state to 0 so you can no longer press it, but if the state of the key is 0, it should not do anything.

Below is the code, any advice would be appreciated.

if(state == 1){
if (customKey){
switch (customKey){
case '0' && player1Avail == 1: {
player1Avail = 0; //make the button unavailable
for (int i = 0; i < 2; i++){leds[button1[i]] = CRGB greenfull;}
for (int i = 0; i < 2; i++){leds[button2[i]] = CRGB redfull;}
for (int i = 0; i < 2; i++){leds[button3[i]] = CRGB redfull;}
Serial.println("player1 buzzed in");
state = 2;
}}}
}

What is the code for other cases going to be ?

Hi, welcome to the forum.
We like to see a full sketch. For example a small sketch that shows the problem.
There is even a website for that: https://snippets-r-us.com/.

Can you put your sketch between lines with three backslash-single-quotes ?

```
Your sketch
```

The if-statement is not the same as a switch-case-statement. That is historically grown that way. I suggest to use if-statements.

No. The value between case and : has to be a compile-time integer constant.
case '0': if (player1Avail == 1) {

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.