WS2812B coding help

Hello,

Im totally new at Arduino and WS2812b. I have found basic coding on link that is good for me.
There are 3 push buttons. When buttons are toggled i want them to change effects (i have it now on link). Now there is just color effect change on press of buttons. When you power Arduino in "standby" i would like "cylon" effect. After one of push buttons is pressed i would like fade in and fade out effect. Like one button, one color with fade in and fade out. I tried to add it but i always get errors. Please if somebody can help with a code. Thanks

Here is Cylon effect for standby when everthing is powered up

void loop() {
  CylonBounce(0xff, 0, 0, 4, 10, 50);
}

void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){

  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }

  delay(ReturnDelay);

  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue);
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
 
  delay(ReturnDelay);
}

And here is fade in and out effect that i would like to have on these three push buttons.

void loop() {
  FadeInOut(0xff, 0x00, 0x00); // red
  FadeInOut(0xff, 0xff, 0xff); // white
  FadeInOut(0x00, 0x00, 0xff); // blue
}

+1 karma for using code tags and clickable links in your first post.

I tried to add it but i always get errors.

Post your best attempt and we can help you correct the errors. Also post the full text of all the errors, in code tags.

Sorry but im not sure how or where to add codes for effects that i said. Im not sure why i cant add "cyclon" effect for standby and "fade" for buttons.

Here is basic code

#include <Adafruit_NeoPixel.h>

#define PIN 2	 // input pin Neopixel is attached to

#define NUMPIXELS      12 // number of neopixels in Ring

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

int delayval = 50; // timing delay

int redColor = 0;
int greenColor = 0;
int blueColor = 0;

int button1 = 0;
int button2 = 0;
int button3 = 0;

void setup() {
  pixels.begin(); // Initializes the NeoPixel library.
//  Serial.begin(9600);
}

void loop() {
  
    button1 = digitalRead(9);
  	if (button1 == HIGH){
      setColor();
  	} else {
  		noColor();
    }
  
  button2 = digitalRead(13);
  	if (button2 == HIGH){
      setColor2();
  	}
  
   button3 = digitalRead(11);
  	if (button3 == HIGH){
      setColor3();
  	}
  

  for(int i=0;i<NUMPIXELS;i++){

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(redColor, greenColor, blueColor)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    //delay(delayval); // Delay for a period of time (in milliseconds).
    
    //Serial.println(i);
    
    
    
  }
}

// setColor()
// picks random values to set for RGB

void setColor(){
  redColor = 255;
  greenColor = 100;
  blueColor = 255;
  
  Serial.print("red: ");
  Serial.println(redColor);
  Serial.print("green: ");
  Serial.println(greenColor);
  Serial.print("blue: ");
  Serial.println(blueColor);
  
}

void setColor2() {
  redColor = 300;
  greenColor = 10;
  blueColor = 0;
};

void setColor3() {
  redColor = 0;
  greenColor = 255;
  blueColor = 255;
};


void noColor() {
  redColor = 0;
  greenColor = 0;
  blueColor = 0;
};

If you are not willing to try, click "report to moderator" and request that the topic is moved to the "gigs and collaborations" forum section. Then modify your original post and add something saying how much you are willing to pay to have the changes done for you.

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