RGBpixel: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
(Added Links section)
(2 intermediate revisions by the same user not shown)
Line 133: Line 133:
== Links ==
== Links ==
* http://www.coolneon.com/
* http://www.coolneon.com/
* http://arduino.cc/en/Reference/SPI
* http://www.idolstarastronomer.com/Home/char-total_control_lighting
* http://www.idolstarastronomer.com/Home/char-total_control_lighting
* https://bitbucket.org/devries/arduino-tcl/overview
* https://bitbucket.org/devries/arduino-tcl/overview
* http://projects.mathfarmer.com/home/12-band-color-organ-rgb-led
* http://projects.mathfarmer.com/home/12-band-color-organ-rgb-led
[[Category:Fort]]

Revision as of 03:36, 21 December 2013

Addressable RGB LED "pixels" from Cool Neon

Wiring

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

CoolNeonRGBpixelWires.jpeg

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;
}

Links