How to have two veriables in a if...else sequence

How can I have two variables for a if...else sequence? For example I have a buttons and a LED, the LED needs to be lit when I press the button in order for something to happen. If one or the other reqirement is not met, the action is not performed. How can I achieve this?
I tryed googling this and for some reason there wasn't an answer.

Edit(after suggestion of posting whole script);
Im currently working with some neopixels, Im still working on the exact way of getting information from the neopixel itself however I think this is how I should do it according to the other replys

//FYI "strip" is the neopixel strip, the following number if information about which pixels on the neopixel to light up
//pinMode is the button
if(strip==4, 255, 0, 0 && pinMode==HIGH){
  strip.setPixelColor(5, 0, 0, 255)//lights up another pixel on neopixel to show that sequence is done
 strip.show(); 
if (a && b && c) {
   do_something;
}

Or

if (a==HIGH && b<4 && c==false) {
   do_something;
}
1 Like

Can you add the code you have already?

I don’t if this helps:
If (cond1 && cond2) then

if(a && b)  - if a *and* b
if(a || b) - if a *or* b 

Please post your entire sketch.

if(a and b)  - if a *and* b
if(a or b) - if a *or* b

Modern C allows you to use the keywords "and" and "or". They are much easier to read.

Im currently working with some neopixels, Im still working on the exact way of getting information from the neopixel itself however I think this is how I should do it according to the other replys

//FYI "strip" is the neopixel strip, the following number if information about which pixels on the neopixel to light up
//pinMode is the button
if(strip==4, 255, 0, 0 && pinMode==HIGH){
  strip.setPixelColor(5, 0, 0, 255)//lights up another pixel on neopixel to show that sequence is done
 strip.show(); 

You can't compare a single varialble 'strip' with a list. Comma separated lists are not valid in C, in this context.

Do not post snippets! Read here to see why:

Why? Anything that is displayed on the Neo, is something you wrote there at some time. It's not unknown to your program.

Do not go back and edit previous posts, if they have already been replied to.

Also, in fact you never did post your entire sketch. Please do so.

Cool, I didn't know that

Sr about that heres by slopply pieced together code:

  #include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(6, 0, NEO_RGB + NEO_KHZ800);
int counter = (0);
int checker = (0);
uint32_t mag = strip.Color(255, 0, 0);

void setup()
{
  strip.begin();
  pinMode(1,INPUT);
}

void loop()
{
//pixels on strips lighting up one by one
 strip.setPixelColor(0, 255, 0, 0);
 strip.show();
  delay(400);
  strip.clear();
  strip.show();
 strip.setPixelColor(1, 255, 0, 0);
 strip.show();
  delay(400);
  strip.clear();
  strip.show();
 strip.setPixelColor(2, 255, 0, 0);
 strip.show();
  delay(400);
  strip.clear();
  strip.show();
 strip.setPixelColor(3, 255, 0, 0);
 strip.show();
  delay(400);
  strip.clear();
  strip.show();
 strip.setPixelColor(4, 255, 0, 0);
 strip.show();
  delay(400);
  strip.clear();
  strip.show();
  if(pinMode == HIGH){
    strip.setPixelColor(5, 255, 0, 0)
      strip.show();
}

I just added the if...else sequence for the button to the end of the code which lights up the Neopixel pixels one after another

Thank you! Now, how does it behave when you run it?

pinMode? Um, seriously? Do you know that it is an official function, pinMode()?

Have you looked at any IDE example sketches, like 'Blink'?

It debugs and gives me these two statements:
40:14 error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
and
41:17 note: in expansion of macro 'HIGH'

No I have not, should I look into it?

You would instantly see the problem if you looked at any of the Button sketches that ship with the IDE.

You should follow some valid learning process. That is one of many. But you used pinMode() already in your sketch, so it should raise a red flag. It seems like you didn't bother to look at any examples or documentation, instead tried to guess.

Any behaviour like that, you are supposed to mention here, without being asked. We are not here to play a game of "100 questions".

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