NeoPixel Ring 16 LED Project Source Code Arduino Programing

Share

NeoPixel ring 16 Led Pattern Arduino code

#include <Adafruit_NeoPixel.h>

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

#define NUMPIXELS      16 // number of neopixels in strip

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

int delay_val = 50; // timing delay in milliseconds

int r = 100;
int g = 100;
int b = 0;



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

}

void loop() {

  for (int i=0; i <3 ; i++){
    setColor();
  for (int j=0; j < NUMPIXELS; j++) {
    
    
    pixels.setPixelColor(j,r,g,b);

    // This sends the updated pixel color to the hardware.
    pixels.show();
     delay(delay_val); 
  }
    delay(delay_val); 
    // off the leds
    
    for (int k=0; k < NUMPIXELS; k++) {
    
    //pixels.setPixelColor(i, pixels.Color(redColor, greenColor, blueColor));
    
    pixels.setPixelColor(k,0,0,0); // off the leds

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

    // Delay for a period of time (in milliseconds).
    delay(20); 
  }

    // Delay for a period of time (in milliseconds).
   // delay(delay_val); 
  }
  pattern1();
  delay(10);

  pattern2();
  delay(10);

  pattern3();
  delay(10);

  pattern4();
  }


// setColor()
// picks random values to set for RGB
void setColor(){
  r = random(0, 255);
  g = random(0,255);
  b = random(0, 255);
}



void pattern1() {
  setColor();
  for (int c = 0; c <= 13; c++) {
    pixels.setPixelColor(c,r,g,b);
    setColor();
    pixels.setPixelColor(c+1,r,g,b);
    setColor();
    pixels.setPixelColor(c+2,r,g,b);
    
    
    
    
    pixels.show();
    delay(100);
    
    
    pixels.setPixelColor(c,0,0,0);
    
    pixels.setPixelColor(c+1,0,0,0);
    pixels.setPixelColor(c+2,0,0,0);
    
    
    pixels.show();
 
      
  }
}

void pattern2() {
  setColor();
  for (int b = 0; b <= 12; b++) {
    pixels.setPixelColor(b,r,g,b);
    setColor();
    pixels.setPixelColor(b+1,r,g,b);
    setColor();
    pixels.setPixelColor(b+2,r,g,b);
    setColor();
    pixels.setPixelColor(b+3,r,g,b);
    
    
    
    pixels.show();
    delay(100);
    
    
    pixels.setPixelColor(b,0,0,0);
    
    pixels.setPixelColor(b+1,0,0,0);
    pixels.setPixelColor(b+2,0,0,0);
    pixels.setPixelColor(b+3,0,0,0);
    
    pixels.show();
 
      
  }
}
void pattern3() {
 
  setColor();
  for (int d = 0; d <= 11; d++) {
    pixels.setPixelColor(d,r,g,b);
    setColor();
    pixels.setPixelColor(d+1,r,g,b);
    setColor();
    pixels.setPixelColor(d+2,r,g,b);
    setColor();
    pixels.setPixelColor(d+3,r,g,b);
    
    setColor();
    pixels.setPixelColor(d+4,r,g,b);
    
    
    pixels.show();
    delay(100);
    
    
    pixels.setPixelColor(d,0,0,0);
    
    pixels.setPixelColor(d+1,0,0,0);
    pixels.setPixelColor(d+2,0,0,0);
    pixels.setPixelColor(d+3,0,0,0);
    pixels.setPixelColor(d+4,0,0,0);
    
    
    pixels.show();
 
      
  }
}




void pattern4() {
 
  setColor();
  for (int a = 0; a <= 10; a++) {
    pixels.setPixelColor(a,r,g,b);
    setColor();
    pixels.setPixelColor(a+1,r,g,b);
    setColor();
    pixels.setPixelColor(a+2,r,g,b);
    setColor();
    pixels.setPixelColor(a+3,r,g,b);
    
    setColor();
    pixels.setPixelColor(a+4,r,g,b);
    setColor();
    pixels.setPixelColor(a+5,r,g,b);
    
    pixels.show();
    delay(100);
    
    
    pixels.setPixelColor(a,0,0,0);
    
    pixels.setPixelColor(a+1,0,0,0);
    pixels.setPixelColor(a+2,0,0,0);
    pixels.setPixelColor(a+3,0,0,0);
    pixels.setPixelColor(a+4,0,0,0);
    pixels.setPixelColor(a+5,0,0,0);
    
    pixels.show();
 
      
  }
}


Neopixel Ring led Patterns Using arduino programing
NeoPixel Circuit

Share
Related  How to connect Arduino IDE To Ardublockly In Windows easy Method

Leave a Reply

Your email address will not be published. Required fields are marked *

Top 5 Most Expensive Domains Ever Sold 4 Must-Try ChatGPT Alternatives: Perplexity AI, BardAI, Pi, and More! Types of Trading Techniques in the Stock Market. ChatGPT app now available in India this AI chatbot can help you make your life more productive. What is wrong with following function code?