multiple buttons

Hi everyone,

I hope everyone is okay. I am working on an arduino project have multiple button on visual studio platform. Can anyone tell me how to control different LEDs from different buttons? I tried to change the inout output parameters but the problem is that they are in same loop? I will add the code as well . can anyone knows anything about it. Please help me as this is urgent? Thanks

void setup() { pinMode(52, OUTPUT);

Serial.begin (9600); }

void loop() { static boolean blink = false; if (Serial.available()) { int val = Serial.read (); if (val == '1') blink = true; // Turn blinker on if (val == '0') blink = false; // Turn blinker off }

if (blink) { digitalWrite(52, HIGH);

delay(500); digitalWrite(52, LOW); delay(500);

}

if (Serial.available()) { int val = Serial.read (); if (val == '2') blink = true; // Turn blinker on if (val == 'a') blink = false; // Turn blinker off }

if (blink) { digitalWrite(51, HIGH);

delay(500); digitalWrite(51, LOW); delay(500);

}

}

If you are trying to blink 2 or more LEDs at different rates then ditch the delay() function and use millis() for timing instead. Have a look at Several things at the same time to see the principles involved. Basically, save the time an action started then every time through loop() check if the required period has elapsed. If so, do something. If not then go round again.

I tried to change the inout output parameters but the problem is that they are in same loop?

Why do you perceive that to be a problem? Just put all the logic in the same "if (Serial.available())" conditional.

I will add the code as well

We prefer code in code tags.

this is urgent?

How so?

You may find the examples in serial input basics useful.

...R