RGBpixel

From Noisebridge
Revision as of 03:36, 21 December 2013 by Thex (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Addressable RGB LED "pixels" from Cool Neon

[edit] Wiring

  • RED - +5v
  • GREEN - Data
  • YELLOW - Clock
  • BLUE - Ground

CoolNeonRGBpixelWires.jpeg

[edit] Code

/*
Developed by: thex (noisebridge)
Updated: 20131122
https://noisebridge.net/wiki/RGBpixel
*/


#include <SPI.h>

int waitTime = 100;
byte maxPower = 0x33;

int offset = 0;

/*
color         hex       r    g    b    deg
==========================================
RED         #FF0000    255,   0, 0      0
ORANGE      #FF7F00    255, 127, 0      30
YELLOW      #FFFF00    255, 255, 0      60
CHARTREUSE  #7FFF00    127, 255, 0      90
GREEN       #00FF00      0, 255, 0      120
SPRING      #00FF7F      0, 255, 127    150
CYAN        #00FFFF      0, 255, 255    180
AZURE       #007FFF      0, 127, 255    210
BLUE        #0000FF      0,   0, 255    240
VIOLET      #7F00FF    127,   0, 255    270
MAGENTA     #FF00FF    255,   0, 255    300
ROSE        #FF007F    255,   0, 127    330
*/

void setup() 
{
  // Set the SPI parameters
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  
  sendEmptyFrame();
}

void loop()
{
  for (int o = 0; o < offset; o++)
    sendColor(maxPower, maxPower, maxPower);
    
  offset++;
  if (offset > 25)
    offset = 0;
    
  for (int i = 0; i < 2; i++)
  {
    // RED
    sendColor(maxPower,0x00,0x00);
    // ORANGE
    sendColor(maxPower, maxPower>>2, 0x00);
    // YELLOW
    sendColor(maxPower, maxPower, 0x00);
    // CHARTREUSE
    sendColor(maxPower>>2, maxPower, 0x00);
    // GREEN
    sendColor(0x00,maxPower,0x00);
    // SPRING
    sendColor(0x00, maxPower, maxPower>>2);
    // CYAN
    sendColor(0x00, maxPower, maxPower);
    // AZURE
    sendColor(0x00, maxPower>>2, maxPower);
    // BLUE
    sendColor(0x00,0x00,maxPower);
    // VIOLOET
    sendColor(maxPower>>2, 0x00, maxPower);
    // MAGENTA
    sendColor(maxPower, 0x00, maxPower);
    // ROSE
    sendColor(maxPower, 0x00, maxPower>>2);
  }
  sendEmptyFrame();
  
  delay(waitTime);
}


// Extrapolated functions from TCL Library

void sendFrame(byte flag, byte red, byte green, byte blue)
{
  SPI.transfer(flag);
  SPI.transfer(blue);
  SPI.transfer(green);
  SPI.transfer(red);
}

void sendColor(byte red, byte green, byte blue)
 {
  byte flag;

  flag = makeFlag(red,green,blue);

  sendFrame(flag,red,green,blue);
}

void sendEmptyFrame()
{
  sendFrame(0x00, 0x00, 0x00, 0x00);
}

byte makeFlag(byte red, byte green, byte blue) 
{
  byte flag = 0;

  flag = (red&0xC0)>>6;
  flag |= ((green&0xC0)>>4);
  flag |= ((blue&0xC0)>>2);
  return ~flag;
}

[edit] Links

Personal tools