RGBpixel

From Noisebridge
Revision as of 19:56, 29 August 2014 by 208.87.217.74 (talk) (→‎Code)
Jump to navigation Jump to search

Addressable RGB LED "pixels" from Cool Neon

Wiring

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

CoolNeonRGBpixelWires.jpeg

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

  • /

// Arduino UNO Default wiring, Yellow to Pin 13 & Green to Pin 11

  1. 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>>1, 0x00);
   // YELLOW
   sendColor(maxPower, maxPower, 0x00);
   // CHARTREUSE
   sendColor(maxPower>>1, maxPower, 0x00);
   // GREEN
   sendColor(0x00,maxPower,0x00);
   // SPRING
   sendColor(0x00, maxPower, maxPower>>1);
   // CYAN
   sendColor(0x00, maxPower, maxPower);
   // AZURE
   sendColor(0x00, maxPower>>1, maxPower);
   // BLUE
   sendColor(0x00,0x00,maxPower);
   // VIOLOET
   sendColor(maxPower>>1, 0x00, maxPower);
   // MAGENTA
   sendColor(maxPower, 0x00, maxPower);
   // ROSE
   sendColor(maxPower, 0x00, maxPower>>1);
 }
 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