Tuesday, 26 November 2024

NeoPioxel Matrix with Arduino

Make Your Own NeoPixel  based 
Scrolling Display using Arduino


Video link: https://youtu.be/qFJ4TIoQ_4o


Library needed: Adafruit_NeoPixel

Arduino Code:

# Basic Program - Part 1

#This program lights all 128 LEDs one by one in sequence 

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

// Which pin on the Arduino is connected to the NeoPixels?
#define PIN   2

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 128


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

#define DELAYVAL 100 // Time (in milliseconds) to pause between pixels

void setup() {
  
#if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif

  pixels.begin();
}
void loop()
{
  pixels.clear(); // Set all pixel colors to 'off'
  for(int i=0; i<NUMPIXELS; i++) 
  {
    pixels.setPixelColor(i, pixels.Color(150, 0, 0));
    pixels.show();   
    delay(DELAYVAL);
   }
}



Part 2:

Video link :
NeoPixel Based Scrolling Display - Part 2  

https://youtu.be/JEcPxMRBh-A


Code To Display '01' :


#include <Adafruit_NeoPixel.h>
#define PIN 2 
#define NUMPIXELS 128
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 100 

void setPixel(int x,int y, int r=150,int g=0,int b=0)
{
  int p=x*16+y;
  pixels.setPixelColor(p, pixels.Color(r,g,b));  
}


void setup() 
{
  pixels.begin();
}

void loop() 
{
    pixels.clear();
    setPixel(0,3);
    setPixel(0,4);
    setPixel(1,2);
    setPixel(1,5);
    setPixel(2,1);
    setPixel(2,6);
    setPixel(3,1);
    setPixel(3,6); 
    setPixel(4,1);
    setPixel(4,6);
    setPixel(5,1);
    setPixel(5,6);    
    setPixel(6,2);
    setPixel(6,5);
    setPixel(7,3);
    setPixel(7,4); 

    setPixel(0,10);
    setPixel(1,9);
    setPixel(1,10);
    setPixel(2,10); 
    setPixel(3,10);
    setPixel(4,10);
    setPixel(5,10);
    setPixel(6,10);
    setPixel(7,10);
    setPixel(7,9);
    setPixel(7,11);                       
    pixels.show();
}


Code To Display colored Pixels :




#include <Adafruit_NeoPixel.h>
#define PIN 2 
#define NUMPIXELS 128
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 100 

void setPixel(int x,int y, int r=150,int g=0,int b=0)
{
  int p=x*16+y;
  pixels.setPixelColor(p, pixels.Color(r,g,b));  
}


void setup() 
{
  pixels.begin();
}

void loop() 
{
    pixels.clear();
    setPixel(3,4,255,255,255); 
    setPixel(5,3,0,255,0); 
    setPixel(1,9,0,0,200); 
    setPixel(6,11,255,0,255);                               
    pixels.show();
    delay(500); 
}


Code To Scroll a vertical bar: 





#include <Adafruit_NeoPixel.h>
#define PIN 2 
#define NUMPIXELS 128
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 100 
int a[8]={0,1,1,0,1,1,1,0};
void setPixel(int x,int y, int r=150,int g=0,int b=0)
{
  int p=x*16+y;
  pixels.setPixelColor(p, pixels.Color(r,g,b));  
}
void setup() 
{
  pixels.begin();
  pixels.clear();
}
void loop() 
{
  for (int j=14; j>3; j--)
  {
    pixels.clear();
    for (int i=0;i<8;i++)
    {
      if(a[i]==0)
         setPixel(i,j,0,0,0);
      if(a[i]==1)
         setPixel(i,j);      
      pixels.show();
    } 
      delay(100);   
  }
}

No comments:

Post a Comment