Switch case by selection with 4 buttons

Good day I have a question times hope someone can help me. It is a switch case requirement. I want to turn on 2 LEDS with 2 buttons. This will be changed later still with 4 buttons. example, if button 1 is pressed then be selected switch case1. if button 2 is pressed then switch case2 should be selected. and so on .. my little exercise to look like my code:

int button1 = 18; int button2 = 19; int LED1 = 26; LED2 int = 28;

void setup () { pinMode (button1, INPUT); pinMode (button2, INPUT); pinMode (LED1, OUTPUT); pinMode (LED2, OUTPUT); }

void loop () {

int state = HIGH; int one = digitalRead (button1); int 2 = digitalRead (button2); switch (state) { case 1: digitalWrite (LED1, HIGH); break; case 2: digitalWrite (LED1, HIGH); break; default: digitalWrite (LED1, LOW); digitalWrite (LED2, LOW);

} }

I constantly told by the case 1 and 2 do not recognize the program What am I doing wrong or do I have to do to make it work? Hope to help. Thank you first for the effort in advance. MFG Mike S

 int 2 = digitalRead (button2);

That'll never compile.

why what I'm doing wrong or what I should change?

Think about it; how is the compiler supposed to know the difference between the number 2 and your variable 2?

Simple. It can’t, so it doesn’t allow the possibility that you call a variable “2”.
It won’t mind “two”, like it didn’t mind “one”

what I’m doing wrong

There’s the lack of code tags, and the code within the switch that isn’t in a case.

if button 2 is pressed then switch case2 should be selected.
and so on …

You can’t just say “and so on” when their is no clear indication as to how these 4 switches will control the LEDs. All we know is that switch 1 turns on LED1, and switch 2 turns on LED 3. What do switch 3 and 4 do?

int LED1 = 26;
LED2 int = 28;

The positions of the variable name and type aren’t interchangeable. The 1st line is correct, the 2nd line isn’t.

int 2 = digitalRead (button2);

Variable names can’t start with a number.

   int state = HIGH;
   switch (state) {

You don’t ever change the value of state, so it will only ever run one of the cases.

The one with the LEDs was just a test program. Actually, I will let run 4 different sequences with the switch case statement.

for example: Button 1 should be run case 1 Button 2 to be run case 2 Button 3 must be run case 3 Button 4 should be run case 4

if no key is pressed is not running are held.

A switch statement isn't the best way to do this since you will have 4 variables. You could do some bit manipulation to stuff those into a single variable, but you're better off using an if/elseif structure. The if/elseif structure will also make it easier to define priority (what happens if both 1 and 2 are pressed at the same time?).

ok I thank you sincerely would have thought that I would be there right away in my sequence 1 with a switch case would be better because Duch a button to push button 1

Actually, it should be a keeper Electronic Bar with 4 buttons 1 button to go to position 1 and take out 2 cl whiskey and drive back 2 key to move to position 1 and 4 cl whiskey get out and drive back 3 key to position 2 and should go out and get 2 cl Vodka drive back Button 3 to move to position 2 and 4 cl Vodka get out and drive back

So I thought I'm drann better with a switch case statement so I only have to install the control flow in my case.

Google translate isn't doing too well - would it be better to post in the German section?

Dortmunder85: So I thought I'm drann better with a switch case statement

Again, a switch statement works with a single variable, not multiple ones. You have multiple variables, ergo, a switch statement is NOT the correct way to go about this. Use if/elseifs so that you can easily define priority.

wie kann ich denn hier in deutsch schreiben?? Wenn ich unten auf deutsch klicke kann ich nirgendwo was schreiben? Wo muss ich da hin??

Achso und Vielen Dank erstmal für diese hervoragenden Antworten Danke