John Bradnam
Published © GPL3+

NeoPixel Mini Cube

This mini cube is made up of six 4x4 WS2812B panels giving a total of 96 individually addressable RGB LEDs.

AdvancedFull instructions provided24 hours2,737
NeoPixel Mini Cube

Things used in this project

Hardware components

WS2812B 4x4 16-Bit Full Color 5050 RGB LED Lamp Panel Light
×6
ATTiny85 SMD
×1
120mAh Lithium Ion battery
×1
1M 0805 resistor
×3
100K 0805 resistor
×1
330R 0805 resistor
×1
1K5 0805 resistor
×1
0.1uF 0805 capacitor
×2
100uf 10V 3528 Tantalum capacitor
×1
AO3401 P-Channel MOSFET SOT-23
×1
2N3904 NPN Transistor SOT-23
×1
0805 Red LED
×1
JST-PH-2-THM-RA socket
×1
5mm mercury switch
×1
M3 x 6mm or 8mm Screw
×24

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

AVR ISP Programmer
Digispark Development System

Story

Read more

Custom parts and enclosures

Panel_Holder.stl

3D print file

Schematics

Schematic

PCB

Eagle Files

Schematic and PCB in Eagle format

Code

MiniCubeV1.ino

C/C++
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

/* Maxtrix Cube
 * jbrad2089@gmail.com
 * 
 *
 *                              00 01 02 03
 *                              07 06 05 04
 *                              08 09 0A 0B
 *                              0F 0E 0D 0C
 *                              ------------
 *  30 31 32 33 | 40 41 42 43 | 10 11 12 13 | 20 21 22 23 
 *  37 36 35 34 | 47 46 45 44 | 17 16 15 14 | 27 26 25 24
 *  38 39 3A 3B | 48 49 4A 4B | 18 19 1A 1B | 28 29 2A 2B
 *  3F 3E 3D 3C | 4F 4E 4D 4C | 1F 1E 1D 1C | 2F 2E 2D 2C 
 *                -----------
 *                50 51 52 53
 *                57 56 55 54
 *                58 59 5A 5B
 *                5F 5E 5D 5C
 */

#define WS2812_PIN PB4
#define LED_PIN PB3
#define POWER_PIN PB2

#define PIXELS 96
#define BRIGHTNESS 8

uint8_t faces[PIXELS];
uint32_t pallete[6];

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXELS, WS2812_PIN, NEO_GRB + NEO_KHZ800);

void(* resetFunc) (void) = 0; //declare reset function @ address 0

void setup() 
{
  //First switch on power
  pinMode(POWER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(POWER_PIN, HIGH);    //Overrides Mercury switch
  digitalWrite(LED_PIN, HIGH);      //Show power is on

  strip.begin();
  strip.setBrightness(BRIGHTNESS);
  strip.show(); // Initialize all pixels to 'off'

  //Set up palette
  pallete[0] = strip.Color(255,0,0);
  pallete[1] = strip.Color(255,255,0);
  pallete[2] = strip.Color(0,255,0);
  pallete[3] = strip.Color(0,255,255);
  pallete[4] = strip.Color(0,0,255);
  pallete[5] = strip.Color(255,0,255);
}

void loop() 
{
  strip.clear();
  
  //colorWipe(strip.Color(255, 255, 255), 50); // white
  //delay(1000);
  
  colorSides(36, 300);
  rainbow2(20);
  rainbow(20);
  rainbowCycle(20);
  strip.clear();
  strip.show();
  delay(500);

  //Power off
  digitalWrite(POWER_PIN, LOW);
  
  delay(1000);
  resetFunc();  //call reset  
}

//Rotate each side with a primary or secondary color
void colorSides(int changes, int wait)
{
  strip.clear();
  for (int j = 0; j < changes; j++)
  {
    for(int s = 0; s < 6; s++)
    {
      for(int i = 0; i < 16; i++) 
      {
        int p = (((s + j) % 6) * 16) + i;
        strip.setPixelColor(p, pallete[s]);
      }
      strip.show();
    }
    delay(wait);
  }
}
  
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) 
{
  for(int i = 0; i < strip.numPixels(); i++) 
  {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

//Display rainbow on all sides
void rainbow(uint8_t wait) 
{
  strip.clear();
  for (int k = 0; k < 5; k++)
  {
    for(int j = 0; j < 256; j++) 
    {
      for (int s = 0; s < 6; s++) //Do for each side
      {
        int b = s * 16;
        uint32_t c = Wheel((b + j) & 255);
        for(int i = 0; i < 16; i++) 
        {
          strip.setPixelColor(b + i, c);
        }
      }
      strip.show();
      delay(wait);
    }
  }
}

//Display rainbow on all sides
void rainbow2(uint8_t wait) 
{
  strip.clear();
  for (int k = 0; k < 5; k++)
  {
    for(int j = 0; j < 255; j++) 
    {
      uint32_t c = Wheel(j);
      for(int i = 0; i < strip.numPixels(); i++) 
      {
        strip.setPixelColor(i, c);
      }
      strip.show();
      delay(wait);
    }
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) 
{
  strip.clear();
  for(int j = 0; j < 256*5; j++) // 5 cycles of all colors on wheel
  { 
    for (int s = 0; s < 6; s++) //Do for each side
    {
      for(int i = 0; i < 16; i++) 
      {
        int p = i + s * 16;
        strip.setPixelColor(p, Wheel(((p * 256 / strip.numPixels()) + j) & 255));
      }
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
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

John Bradnam

John Bradnam

141 projects • 167 followers

Comments