RGBpixel: Difference between revisions

From Noisebridge
Jump to navigation Jump to search
(Added arduino code sample for test pattern)
Line 12: Line 12:


<pre>
<pre>
/*
Developed by: thex (noisebridge)
Updated: 20131122
https://noisebridge.net/wiki/RGBpixel
*/
#include <SPI.h>
#include <SPI.h>
int waitTime = 100;
byte maxPower = 0x33;


int offset = 0;
int offset = 0;


void setup() {
/*
  // put your setup code here, to run once:
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
   // Set the SPI parameters
   SPI.begin();
   SPI.begin();
Line 28: Line 54:
}
}


void loop() {
void loop()
  byte power = 0xff;
{
  // put your main code here, to run repeatedly:
   for (int o = 0; o < offset; o++)
   for (int o = 0; o < offset; o++)
     sendColor(power, power, power);
     sendColor(maxPower, maxPower, maxPower);
      
      
   offset++;
   offset++;
   if (offset > 2)
   if (offset > 25)
     offset = 0;
     offset = 0;
      
      
   for (int i = 0; i < 9; i++)
   for (int i = 0; i < 2; i++)
   {
   {
     sendColor(power,0x00,0x00);
    // RED
     sendColor(0x00,power,0x00);
     sendColor(maxPower,0x00,0x00);
     sendColor(0x00,0x00,power);
    // 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();
   sendEmptyFrame();
    
    
   delay(100);
   delay(waitTime);
}
}


// Extrapolated functions from TCL Library
// Extrapolated functions from TCL Library
Line 59: Line 106:
}
}


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


Line 72: Line 120:
}
}


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



Revision as of 05:28, 22 November 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;
}