Hackster is hosting Impact Spotlights: Smart Home. Watch the stream live on Thursday!Hackster is hosting Impact Spotlights: Smart Home. Stream on Thursday!
Arnov Sharma
Published © LGPL

WS2812B RGB LED in Circuits

Learn how to use WS2812B RGB LED in custom circuits

BeginnerFull instructions provided1 hour12,662

Things used in this project

Story

Read more

Schematics

sch

Code

Rainbow

C/C++
#include <Adafruit_NeoPixel.h>

#define PIXEL_PIN    2   // Digital IO pin connected to the NeoPixels.//D4 - 2

#define PIXEL_COUNT 6 

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);


void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
rainbow(20);
}



void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Credits

Arnov Sharma
328 projects • 332 followers
Just your average MAKER
Contact

Comments

Please log in or sign up to comment.