I am trying to make a code where there are if statements and when you press a button, if some things are true, then a green light goes on. I also want it to turn a red light on when the same button is pressed but other things are true. So far, when I tried it it only followed the first set and totally disregarded the second one. Please help!

I havn't been coding for very long (like 4 days ) but that loks really confusing to me, maybe it's because i don't see the rest or how the other variables are being derived i can't see the flow. any whoooo

IMHO it looks like you only want to turn on 'led' if all of the first statements are true.. in which case jezuz has it pegged, work it just like you set up the || in the bottom statement for 'ledtwo' but use && instead.

Just curious...

how can 'redvalue + 30' be >= to 'redVal' just befor you are testing to see if 'redvalue - 30' is <= to 'redVal' with nothing in between to change either of those values? same goes for the other values for each color and both LED's.... like i said maybe it's because i can't see the rest of the code but i can't seem to understand your flow.

When you start nesting if()s that deeply then it is a good indication that you haven't thought your program's logic flow and structure through far enough.

For logic flow: go ahead and draw a flowchart of the desired behavior. If your logic really is that hairy then you'll be glad of the time spent doing so when you get to implementing. If it isn't then it will become apparent that you went overboard on the if() statements and you'll be glad of the time not spent troubleshooting that mess.

This is quite meaningless -- why are you comparing redvalue to redVal? They're both red values! What the heck does this mean? How is anyone supposed to know how and why redvalue and redVal differ? It makes no sense.

I don't care what the values are named and about everything else. I just want to know how to make both the parts work because no matter what, led2 will never go on but if the criteria is met, the first led will.

I don't care what the values are named and about everything else. I just want to know how to make both the parts work because no matter what, led2 will never go on but if the criteria is met, the first led will.

Without the full code you're trying to get working and a thorough description of what you're trying to accomplish no one here is going to be able to help you. Based on the fragment you provided I offered some suggestions on how you might get to the solution you're looking for. If that's not enough to get you going then you have two real options. 1) Post full code and a description of what you want to do -or- 2) break the problem down into the smallest thing you don't know how to do, post full code and a description for that and ask a specific question about that.

But right now no one can help you because no one seems to understand what your problem is because you've asked broad and vague questions with fragmentary code to examine.

It is long and sorry there are no comments but this is what it is for: I am trying to make a "game" of sorts where there are two rgb leds. One turns on to a random color. The other one, you have to try and make as close to the other one's color by using the 3 sliding potentiometers. There is a button to press that when pressed, will turn a red led(ledtwo) on if the values of the led are not within 30 "units". If the colors are close enough, the green led will turn on(led). The green led will turn on if the conditions are met, however, the red led wil not turn on no matter what. I know it's confusing but thank you for your help so far and I hope you can help me fix this. P.S. the serial printing is just there for testing purposes, it has no role in the real sketch.

if( (val==val2) && (val!=LOW) ) { if( (deltaRed<=30) && (deltaGreen<=30) && (deltaBlue<=30) ) { // Do what you want to do if the guess was right and in bounds } { // Do what you want to do if the guess was wrong and out of bounds } }}

Hi,I don't have much experience in coding and I don't even have an Arduino yet but one question I have on this code is;Could you use an else statement since as I understand it if all the conditions are correct you want to light the "correct" led ELSE you want to light the "incorrect" led indicating a wrong guess. Would this work and if not can someone correct me.As I said I have limited experience in coding (mechanical engineering mantra if you can't physically see something working it must be some kind of witchcraft/magic )

Edit: Just read that last code, and it looks like my comments might not have been needed. But to clear something up, is the "else" implied as part of the "if" statement? if(something == something}){do this}{else do this}