RGBpixel

From Noisebridge
(Difference between revisions)
Jump to: navigation, search
(Created page with "Addressable RGB LED "pixels" from Cool Neon == Wiring == * RED - +5v * GREEN - Data * YELLOW - Clock * BLUE - Ground 400px")
 
(Added arduino code sample for test pattern)
Line 8: Line 8:
  
 
[[File:CoolNeonRGBpixelWires.jpeg|400px]]
 
[[File:CoolNeonRGBpixelWires.jpeg|400px]]
 +
 +
== Code ==
 +
 +
<pre>
 +
#include <SPI.h>
 +
 +
int offset = 0;
 +
 +
void setup() {
 +
  // put your setup code here, to run once:
 +
 
 +
  // Set the SPI parameters
 +
  SPI.begin();
 +
  SPI.setBitOrder(MSBFIRST);
 +
  SPI.setDataMode(SPI_MODE0);
 +
  SPI.setClockDivider(SPI_CLOCK_DIV2);
 +
 
 +
  sendEmptyFrame();
 +
}
 +
 +
void loop() {
 +
  byte power = 0xff;
 +
  // put your main code here, to run repeatedly:
 +
  for (int o = 0; o < offset; o++)
 +
    sendColor(power, power, power);
 +
   
 +
  offset++;
 +
  if (offset > 2)
 +
    offset = 0;
 +
   
 +
  for (int i = 0; i < 9; i++)
 +
  {
 +
    sendColor(power,0x00,0x00);
 +
    sendColor(0x00,power,0x00);
 +
    sendColor(0x00,0x00,power);
 +
  }
 +
  sendEmptyFrame();
 +
 
 +
  delay(100);
 +
}
 +
 +
// 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;
 +
}
 +
</pre>

Revision as of 03:26, 22 November 2013

Addressable RGB LED "pixels" from Cool Neon

Wiring

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

CoolNeonRGBpixelWires.jpeg

Code

#include <SPI.h>

int offset = 0;

void setup() {
  // put your setup code here, to run once:
  
  // Set the SPI parameters
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  
  sendEmptyFrame();
}

void loop() {
  byte power = 0xff;
  // put your main code here, to run repeatedly:
  for (int o = 0; o < offset; o++)
    sendColor(power, power, power);
    
  offset++;
  if (offset > 2)
    offset = 0;
    
  for (int i = 0; i < 9; i++)
  {
    sendColor(power,0x00,0x00);
    sendColor(0x00,power,0x00);
    sendColor(0x00,0x00,power);
  }
  sendEmptyFrame();
  
  delay(100);
}

// 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;
}
Personal tools