BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

How to set one colour of neopixels when a button is pressed in blynk app

Hi, I am trying to control neopixels using a Node MCU and the Blynk app but I do not want to use ZeRGBa I just want to set the colour of the pixels (for instance red) when a button is pressed inside the Blynk app, I think it would be as simple as an if statement but I have tried doing it that way like setting the pin the button is connecting to (in this case digital pin 2) then writing an if statement that states if digital pin 2 is high then set colour of pixels to red but this did not work, the button when pressed didn’t do anything.
I hope someone can help with my issue, thank you.

You should use virtual pins rather than digital, and get the value of the switch widget using the param.asInt() command.

Pete.

Can you give me an example of that would look like?
thank you

If you search for the keywords I’ve given you, you will find many examples.
There are also examples in the Sketch Builder.

Pete.

Okay thank you i will take a look

Hi, I have tried setting the colour of the neopixels using a button in the Blynk app but the less didn’t light up at all. This is my code:

BLYNK_WRITE(V2){
  int Power = param.asInt();
  if(Power == HIGH){
    strip.Color(255, 0, 0);
  }else{
    strip.clear();
  }
  strip.show();
}

can somebody please help me as to why the pixels aren’t lighting up?

@Luke8900 please edit your code, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Pete.

There you go I have edited the code.
I forgot to include that I edited the code to print a value to the serial monitor when the button is pressed in the app. which worked fine but the pixels didn’t light up at all.