WS2801 36mm LED Pixel R and G Switched

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
onyex
 
Posts: 6
Joined: Mon Aug 11, 2014 12:14 pm

WS2801 36mm LED Pixel R and G Switched

Post by onyex »

Hello everyone,
I am having some issues with some WS2801 pixels. I purchased some WS2801s about two years ago. They worked well for the project but I decided to slightly expand on what I already had. So I purchased some more recently and got them set up and plugged them in and got this: http://i.imgur.com/kuVe6SL.jpg. All of the pixels are set to green. The ones that are green are the ones I have used previously, the red ones are new WS2801s. Does anyone have any recommendations for fixing this?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: WS2801 36mm LED Pixel R and G Switched

Post by adafruit_support_bill »

If you are using the Adafruit WS2801 library, just specify the WS2801_GRB option in the constructor. (The default is WS2801_RGB)

Code: Select all

  // Configurable pins:
  Adafruit_WS2801(uint16_t n, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);
  Adafruit_WS2801(uint16_t x, uint16_t y, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);

User avatar
onyex
 
Posts: 6
Joined: Mon Aug 11, 2014 12:14 pm

Re: WS2801 36mm LED Pixel R and G Switched

Post by onyex »

adafruit_support_bill wrote:If you are using the Adafruit WS2801 library, just specify the WS2801_GRB option in the constructor. (The default is WS2801_RGB)

Code: Select all

  // Configurable pins:
  Adafruit_WS2801(uint16_t n, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);
  Adafruit_WS2801(uint16_t x, uint16_t y, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB);

Currently I am using the WS2801_GRB currently, in my old .cpp there was no

Code: Select all

Adafruit_WS2801(uint16_t x, uint16_t y, uint8_t dpin, uint8_t cpin, uint8_t order=WS2801_RGB)
I just updated the .cpp and .h. It seems to have caused another issue.

Code: Select all

Adafruit_WS2801 strip = Adafruit_WS2801(78, dataPinLED, clockPinLED, WS2801_GRB);
has an error message coming up saying "call overloaded '...' is ambiguous"

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: WS2801 36mm LED Pixel R and G Switched

Post by adafruit_support_bill »

Is that the only error message? Be sure to scroll to the top and get the first few if there are more than one.

Also, post the code that you are using.

User avatar
onyex
 
Posts: 6
Joined: Mon Aug 11, 2014 12:14 pm

Re: WS2801 36mm LED Pixel R and G Switched

Post by onyex »

Code: Select all

//Credit to Ben Moyes in regards to spectrum analizer
//Credit to Laurid Meyer in regards to the Android code and ethernet code
//Credit to David Kavanagh in regards to the Adafruit LED cubes
//Credit to Mike LaGrasta for origional concept and some origional code
#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_WS2801.h>

//Set a MAC address for the ethernet Arduino  eg. DE:AD:BE:EF:FE:EE
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE };
//Set the IP address for the ethernet Arduino  eg. 192.168.1.105
IPAddress serverIP(192,168,1,105);
//Set the port for the ethernet Arduino to communicate through  eg. 8888
int serverPort = 8888;

//Spectrum Constants
int strobe = 4; // strobe pins on digital 4
int res = 5; // reset pins on digital 5
int left[7]; // store band values in these arrays
int right[7];
int band=0;

//LED Constants
int dataPinLED = 2;
int clockPinLED = 3;

int red_Slider=0;
int green_Slider=0;
int blue_Slider=0;

char key[8];
int keyset = 0;

int audioFlag = 0;

//String queue where commands are stored in order
String commandStr = "";

//Initialize strip 
  Adafruit_WS2801 strip = Adafruit_WS2801(78, dataPinLED, clockPinLED, WS2801_GRB);
  Adafruit_WS2801 strip = Adafruit_WS2801(6, 13, dataPinLED, clockPinLED, WS2801_GRB);


//Set default patern
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int defaultPattern = 9;////////////////////////////////////////////////////////////////ಠ_ಠ///////////////////////// change pattern here
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Test patern flag variable
bool defaultTestPattern = false;

// Initialize the Ethernet server library
// with the IP address and port you want to use 
EthernetServer server(serverPort);

void setup()
{
  
  //begin serial
  Serial.begin(9600);
  //Start the ethernet server
  Ethernet.begin(mac,serverIP);
  server.begin();
  Serial.println(" ----- Server has started ----- ");
  strip.begin();
  Serial.println(" ---- Light strips started ---- ");
  pinMode(res, OUTPUT); // reset
  pinMode(strobe, OUTPUT); // strobe
  digitalWrite(res,LOW); // reset low
  digitalWrite(strobe,HIGH); //pin 5 is RESET on the shield
  while(defaultTestPattern)
  {
    lightTest();
  }
}

void loop()
{
  //Listen for client
  EthernetClient client = server.available();
  if (client)//if connected
  {
    while (client.connected())//if the client is connected
    {
      readMSGEQ7();
      if(client.available())//if client is available
      {
        //reads the inputs from the client
        char c = client.read();
        //concatonates the commands into a string
        commandStr += c;
        if (c == '\n') //if new line, complete command
        {
          Serial.println(commandStr); //outputs a single command line
          if (commandStr.indexOf("RGB Slider: ") == 0) //if the command begins with set (yes, I know you shouldn't compare strings like that)
          {
            audioFlag = 0;
            String value = commandStr; //store the command into a new String
            value.replace("RGB Slider: ", ""); //removes set from the string and replaces it with a space
            Serial.println(value);
            tokenizeRGB(value);
            colorAll(Color(red_Slider, green_Slider, blue_Slider));
          }
          if (commandStr.indexOf("Audio") == 0) //if the command begins with set (yes, I know you shouldn't compare strings like that)
          {
            audioFlag = 1;
            Serial.print("Flag: ");
            Serial.print(audioFlag);
          }
          commandStr = ""; //resets the command queue
        }
      }
      if ( audioFlag == 1)
      {
        BANNED();
        strip.show();
      }
    }
    //Woh, slow down there. You gotta give time for the data to send
    delay(1);
    //close the connection
    client.stop();
  }
  else 
  {
    switch(defaultPattern) 
    {
      case (1):
        p_rainbow();
        break;
      case (2):
        p_cylon();
        break;
      case (3):
        p_random(0);
        break;
      case (4):
        colorLines();
        break;
      case (5):
        lightChaser();
        break;
      case (6):
        p_christmascolors();
        break;
      case (7):
        p_winterwonderland();
        break;
      case (8):
        timedpatten();
        break;
      case (9):
        p_solidgreen();
        break;
    }
  }
}

void timedpatten()
{
  int multiplier = 1;
  int time = millis()/(300000 * multiplier);
  if (time >= 5)
  {
    multiplier++;
    time = 0;
  }
  if (time == 0)
  {
    p_rainbow();
  }
  else if (time == 1)
  {
    p_random(5);
  }
  else if (time == 2)
  {
    colorLines();
  }
  else if (time == 3)
  {
    lightChaser();
  }
  else if (time == 4)
  {
    p_cylon();
  }
}

void BANNED()
{
  Serial.print("Left: ");
  for (band = 0; band < 7; band++)
  {
    Serial.print(left[band]);
    Serial.print(" ");
  }
  Serial.println();
  // display values of right channel on serial monitor
  Serial.print("Right: ");
  for (band = 0; band < 7; band++)
  {
    Serial.print(right[band]);
    Serial.print(" ");
  }
  Serial.println();
  Serial.println();
  
  lightOrgan();
}

void readMSGEQ7() // Function to read 7 band equalizers
{
  digitalWrite(res, HIGH);
  digitalWrite(res, LOW);
  for (band = 0; band < 7; band++)
  {
    digitalWrite(strobe,LOW); // strobe pin on the shield - kicks the IC up to the next band 
    delayMicroseconds(30); // 
    left[band] = analogRead(0); // store left band reading
    right[band] = analogRead(1); // ... and the right
    digitalWrite(strobe,HIGH); 
  }
}

void tokenizeRGB (String value)
{ 
  String temp = "";
  int i = 0;
  while (value.charAt(i) != ' ')
  {
    temp += value.charAt(i);
    i++;
  }
  temp += value.charAt(i+1);
  red_Slider = convertToInt(temp);

  i = i+1;
  temp = "";
  while (value.charAt(i) != ' ')
  {
    temp += value.charAt(i);
    i++;
  }
  temp += value.charAt(i+1);
  green_Slider = convertToInt(temp);

  i = i+1;
  temp = "";
  while (value.charAt(i) != '\n')
  {
    temp += value.charAt(i);
    i++;
  }
  temp += value.charAt(i+1);
  blue_Slider = convertToInt(temp);

  Serial.println(red_Slider);
  Serial.println(green_Slider);
  Serial.println(blue_Slider);
}

int convertToInt(String value)
{
  char buf[value.length()];
  value.toCharArray(buf,value.length());
  return atoi(buf);
}

// ascii hex to rgb
// in is a RGB hex color string "ff00ff"
// out is a 3 cell int array in which to store the result
// this is NOT a fast function, use it sparingly and not in tight loops
void ah2rgb(char * in, int * out) 
{
  char hr[3];
  char hg[3];
  char hb[3];
  hr[0] = in[0];
  hr[1] = in[1];
  hr[2] = 0;
  hg[0] = in[2];
  hg[1] = in[3];
  hg[2] = 0;
  hb[0] = in[4];
  hb[1] = in[5];
  hb[2] = 0;

  out[0] = (int) strtol(hr, NULL, 16);
  out[1] = (int) strtol(hg, NULL, 16);
  out[2] = (int) strtol(hb, NULL, 16);
}

// ascii hex to "Color", much faster
uint32_t ah2c(char * in) 
{
  int rgb[3];
  ah2rgb(in, rgb);
  return Color(rgb[0], rgb[1], rgb[2]);
}

// this takes x/y coordinates and maps it to a pixel offset
// just for ease of making patterns
int g2p(int x, int y) 
{
  int grid[6][13] = 
   {{77,66,65,54,53,42,41,30,29,18,17, 6, 5}
   ,{76,67,64,55,52,43,40,31,28,19,16, 7, 4}
   ,{75,68,63,56,51,44,39,32,27,20,15, 8, 3}
   ,{74,69,62,57,50,45,38,33,26,21,14, 9, 2}
   ,{73,70,61,58,49,46,37,34,25,22,13,10, 1}
   ,{72,71,60,59,48,47,36,35,24,23,12,11, 0}
  };
  return grid[y][x];
}

// fade from off to "target" rgb values (currently un-used, not well tested but should be right)
void off2rgb(int tr, int tg, int tb) 
{
  colorAll(Color(0,0,0));
  int r = 0;
  int g = 0;
  int b = 0;
  while (r < tr | g < tg | b < tb) {
    if (r < tr) 
    { 
      r++; 
    }
    if (g < tg) 
    { 
      g++; 
    }
    if (b < tb) 
    { 
      b++; 
    }
    colorAll(Color(r,g,b));
  }
}

// fade from rgb color to off
void rgb2off(int r, int g, int b) 
{
  while ( r > 0 | g > 0 | b > 0) 
  {
    if (r > 0) 
    { 
      r--; 
    }
    if (g > 0) 
    { 
      g--; 
    }
    if (b > 0) 
    { 
      b--; 
    }
    colorAll(Color(r,g,b));
  }
}

// set all pixels to a "Color" value
void colorAll(uint32_t c) 
{
  int i;
  for (i=0; i < strip.numPixels(); i++) 
  {
    strip.setPixelColor(i, c);
  }
  strip.show();
}

// set all pixels to a "Color" value, one at a time, with a delay
void colorWipe(uint32_t c, uint8_t wait) 
{
  int i;
  for (i=0; i < strip.numPixels(); i++) 
  {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

// create the "Color" value from RBG, Adafruit code
uint32_t Color(byte r, byte g, byte b) 
{
  // Create a 24 bit color value from R,G,B
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}

//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(byte WheelPos)
{
  if (WheelPos < 85) 
  {
    return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if (WheelPos < 170) 
  {
    WheelPos -= 85;
    return Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  else 
  {
    WheelPos -= 170; 
    return Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

/************** PATTERNS ****************/

void p_christmascolors()
{
  int i = random(0,2);

  switch (i)
  {
    case(0):

    strip.setPixelColor(random(0,strip.numPixels()), Color(255,0,0));
    strip.show();
    break;

    case (1):

    strip.setPixelColor(random(0,strip.numPixels()), Color(0,255,0));
    strip.show();
    break;

  }
  delay (20);
}


void p_winterwonderland()
{
  int i = random(0,2);

  switch (i)
  {
    case(0):

    strip.setPixelColor(random(0,strip.numPixels()), Color(0,0,255));
    strip.show();
    break;

    case (1):

    strip.setPixelColor(random(0,strip.numPixels()), Color(255,255,255));
    strip.show();
    break;
  }
  delay (20);
}

void p_solidgreen ()
{
  for (int i=0;i<78;i++)
  {
    strip.setPixelColor(i,0,255,0);
  }
  strip.show();
}

// random pixel, random color
void p_random (int wait) 
{
  strip.setPixelColor(random(0, strip.numPixels()),Color(random(0,255), random(0,255), random(0,255)));
  strip.show();
  delay(wait);
}

// RAINBOW TABLE
void p_rainbow() 
{
  int i, j;
  for (j=0; j < 256; j++) 
  {
    for (i=0; i < strip.numPixels(); i++) 
    {
      strip.setPixelColor(i, Wheel( ((i * 256 / strip.numPixels()) + j) % 256) );
    }  
    strip.show();
  }
}

// sweeping red lights with a trail (needs fixing)
void p_cylon() 
{
  uint32_t colors[4] = {Color(255,0,0), Color(150,0,0), Color(50,0,0), Color(0,0,0)};
  int wait = 100;
  int i;
  int j;
  for (i=0; i<13; i++) 
  {
    for (j=0; j<4; j++) 
    {
      int x = i-j;
      if (x < 40) 
      {
        strip.setPixelColor(g2p(x,0), colors[j]);
        strip.setPixelColor(g2p(x,1), colors[j]);
        strip.setPixelColor(g2p(x,2), colors[j]);
        strip.setPixelColor(g2p(x,3), colors[j]);
      }
    }
    strip.show();
    delay(wait);
  }
  for (i=10; i>-3; i--) 
  {
    for (j=0; j<4; j++) 
    {
      int x = i+j;
      if (x < 40) 
      { // max x value, ought to be a var
        strip.setPixelColor(g2p(i+j,0), colors[j]);
        strip.setPixelColor(g2p(i+j,1), colors[j]);
        strip.setPixelColor(g2p(i+j,2), colors[j]);
        strip.setPixelColor(g2p(i+j,3), colors[j]);
      }
    }
    strip.show();
    delay(wait);
  }
}

// Additional possibility. Initial code for visual equalizer
void colorLines() 
{
  int i;
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,0), Color(255,0,0));
  }
  strip.show();
  delay(500);
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,1), Color(0,255,0));
  }
  strip.show();
  delay(500);
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,2), Color(0,0,255));
  }
  strip.show();
  delay(500);
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,3), Color(255,255,255));
  }
  strip.show();
  delay(500);
  colorWipe(Color(0, 0, 0), 50);
}

// sweep all color extremes through all pixels (to find off color pixels)
void lightTest() 
{
  colorWipe(Color(255, 0, 0), 50);
  colorWipe(Color(0, 255, 0), 50);
  colorWipe(Color(0, 0, 255), 50);
  colorWipe(Color(255, 255, 255), 50);
  colorWipe(Color(0, 0, 0), 50);
}

// Random lights. Could do better with the coding but I got lazy.
void lightChaser() 
{
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
}


void lightOrgan()
{
  if (left[1] < 255)
  {
    strip.setPixelColor(39,left[1],0,255-left[1]);
    strip.setPixelColor(38,0,0,0);
    strip.setPixelColor(37,0,0,0);
    strip.setPixelColor(36,0,0,0);
  }
  else if (left[1] < 551)
  {
    strip.setPixelColor(39,255,0,0);
    strip.setPixelColor(38,left[1]-256,0,511-left[1]);
    strip.setPixelColor(37,0,0,0);
    strip.setPixelColor(36,0,0,0);
  }
  else if (left[1] < 767)
  {
    strip.setPixelColor(39,255,0,0);
    strip.setPixelColor(38,255,0,0);
    strip.setPixelColor(37,left[1]-512,0,767-left[1]);
    strip.setPixelColor(36,0,0,0);
  }
  else if (left[1] < 1023)
  {
    strip.setPixelColor(39,255,0,0);
    strip.setPixelColor(38,255,0,0);
    strip.setPixelColor(37,255,0,0);
    strip.setPixelColor(36,left[1]-768,0,1023-left[1]);
  }


  if (left[2] < 255)
  {
    strip.setPixelColor(32,left[2],0,255-left[2]);
    strip.setPixelColor(33,0,0,0);
    strip.setPixelColor(34,0,0,0);
    strip.setPixelColor(35,0,0,0);
  }
  else if (left[2] < 551)
  {
    strip.setPixelColor(32,255,0,0);
    strip.setPixelColor(33,left[2]-256,0,511-left[2]);
    strip.setPixelColor(34,0,0,0);
    strip.setPixelColor(35,0,0,0);
  }
  else if (left[2] < 767)
  {
    strip.setPixelColor(32,255,0,0);
    strip.setPixelColor(33,255,0,0);
    strip.setPixelColor(34,left[2]-512,0,767-left[2]);
    strip.setPixelColor(35,0,0,0);
  }
  else if (left[2] < 1023)
  {
    strip.setPixelColor(32,255,0,0);
    strip.setPixelColor(33,255,0,0);
    strip.setPixelColor(34,255,0,0);
    strip.setPixelColor(35,left[2]-768,0,1023-left[2]);
  }


  if (left[3] < 255)
  {
    strip.setPixelColor(31,left[3],0,255-left[3]);
    strip.setPixelColor(30,0,0,0);
    strip.setPixelColor(29,0,0,0);
    strip.setPixelColor(28,0,0,0);
  }
  else if (left[3] < 551)
  {
    strip.setPixelColor(31,255,0,0);
    strip.setPixelColor(30,left[3]-256,0,511-left[3]);
    strip.setPixelColor(29,0,0,0);
    strip.setPixelColor(28,0,0,0);
  }
  else if (left[3] < 767)
  {
    strip.setPixelColor(31,255,0,0);
    strip.setPixelColor(30,255,0,0);
    strip.setPixelColor(29,left[3]-512,0,767-left[3]);
    strip.setPixelColor(28,0,0,0);
  }
  else if (left[3] < 1023)
  {
    strip.setPixelColor(31,255,0,0);
    strip.setPixelColor(30,255,0,0);
    strip.setPixelColor(29,255,0,0);
    strip.setPixelColor(28,left[3]-768,0,1023-left[3]);
  }


  if (left[4] < 255)
  {
    strip.setPixelColor(24,left[4],0,255-left[4]);
    strip.setPixelColor(25,0,0,0);
    strip.setPixelColor(26,0,0,0);
    strip.setPixelColor(27,0,0,0);
  }
  else if (left[4] < 551)
  {
    strip.setPixelColor(24,255,0,0);
    strip.setPixelColor(25,left[4]-256,0,511-left[4]);
    strip.setPixelColor(26,0,0,0);
    strip.setPixelColor(27,0,0,0);
  }
  else if (left[4] < 767)
  {
    strip.setPixelColor(24,255,0,0);
    strip.setPixelColor(25,255,0,0);
    strip.setPixelColor(26,left[4]-512,0,767-left[4]);
    strip.setPixelColor(27,0,0,0);
  }
  else if (left[4] < 1023)
  {
    strip.setPixelColor(24,255,0,0);
    strip.setPixelColor(25,255,0,0);
    strip.setPixelColor(26,255,0,0);
    strip.setPixelColor(27,left[4]-768,0,1023-left[4]);
  }


  if (left[5] < 255)
  {
    strip.setPixelColor(23,left[5],0,255-left[5]);
    strip.setPixelColor(22,0,0,0);
    strip.setPixelColor(21,0,0,0);
    strip.setPixelColor(20,0,0,0);
  }
  else if (left[5] < 551)
  {
    strip.setPixelColor(23,255,0,0);
    strip.setPixelColor(22,left[5]-256,0,511-left[5]);
    strip.setPixelColor(21,0,0,0);
    strip.setPixelColor(20,0,0,0);
  }
  else if (left[5] < 767)
  {
    strip.setPixelColor(23,255,0,0);
    strip.setPixelColor(22,255,0,0);
    strip.setPixelColor(21,left[5]-512,0,767-left[5]);
    strip.setPixelColor(20,0,0,0);
  }
  else if (left[5] < 1023)
  {
    strip.setPixelColor(23,255,0,0);
    strip.setPixelColor(22,255,0,0);
    strip.setPixelColor(21,255,0,0);
    strip.setPixelColor(20,left[5]-768,0,1023-left[5]);
  }


  if (right[5] < 255)
  {
    strip.setPixelColor(16,right[5],0,255-right[5]);
    strip.setPixelColor(17,0,0,0);
    strip.setPixelColor(18,0,0,0);
    strip.setPixelColor(19,0,0,0);
  }
  else if (right[5] < 551)
  {
    strip.setPixelColor(16,255,0,0);
    strip.setPixelColor(17,right[5]-256,0,511-right[5]);
    strip.setPixelColor(18,0,0,0);
    strip.setPixelColor(19,0,0,0);
  }
  else if (right[5] < 767)
  {
    strip.setPixelColor(16,255,0,0);
    strip.setPixelColor(17,255,0,0);
    strip.setPixelColor(18,right[5]-512,0,767-right[5]);
    strip.setPixelColor(19,0,0,0);
  }
  else if (right[5] < 1023)
  {
    strip.setPixelColor(16,255,0,0);
    strip.setPixelColor(17,255,0,0);
    strip.setPixelColor(18,255,0,0);
    strip.setPixelColor(19,right[5]-768,0,1023-right[5]);
  }


  if (right[4] < 255)
  {
    strip.setPixelColor(15,right[4],0,255-right[4]);
    strip.setPixelColor(14,0,0,0);
    strip.setPixelColor(13,0,0,0);
    strip.setPixelColor(12,0,0,0);
  }
  else if (right[4] < 551)
  {
    strip.setPixelColor(15,255,0,0);
    strip.setPixelColor(14,right[4]-256,0,511-right[4]);
    strip.setPixelColor(13,0,0,0);
    strip.setPixelColor(12,0,0,0);
  }
  else if (right[4] < 767)
  {
    strip.setPixelColor(15,255,0,0);
    strip.setPixelColor(14,255,0,0);
    strip.setPixelColor(13,right[4]-512,0,767-right[4]);
    strip.setPixelColor(12,0,0,0);
  }
  else if (right[4] < 1023)
  {
    strip.setPixelColor(15,255,0,0);
    strip.setPixelColor(14,255,0,0);
    strip.setPixelColor(13,255,0,0);
    strip.setPixelColor(12,right[4]-768,0,1023-right[4]);
  }


  if (right[3] < 255)
  {
    strip.setPixelColor(8,right[3],0,255-right[3]);
    strip.setPixelColor(9,0,0,0);
    strip.setPixelColor(10,0,0,0);
    strip.setPixelColor(11,0,0,0);
  }
  else if (right[3] < 551)
  {
    strip.setPixelColor(8,255,0,0);
    strip.setPixelColor(9,right[3]-256,0,511-right[3]);
    strip.setPixelColor(10,0,0,0);
    strip.setPixelColor(11,0,0,0);
  }
  else if (right[3] < 767)
  {
    strip.setPixelColor(8,255,0,0);
    strip.setPixelColor(9,255,0,0);
    strip.setPixelColor(10,right[3]-512,0,767-right[3]);
    strip.setPixelColor(11,0,0,0);
  }
  else if (right[3] < 1023)
  {
    strip.setPixelColor(8,255,0,0);
    strip.setPixelColor(9,255,0,0);
    strip.setPixelColor(10,255,0,0);
    strip.setPixelColor(11,right[3]-768,0,1023-right[3]);
  }


  if (right[2] < 255)
  {
    strip.setPixelColor(7,right[2],0,255-right[2]);
    strip.setPixelColor(6,0,0,0);
    strip.setPixelColor(5,0,0,0);
    strip.setPixelColor(4,0,0,0);
  }
  else if (right[2] < 551)
  {
    strip.setPixelColor(7,255,0,0);
    strip.setPixelColor(6,right[2]-256,0,511-right[2]);
    strip.setPixelColor(5,0,0,0);
    strip.setPixelColor(4,0,0,0);
  }
  else if (right[2] < 767)
  {
    strip.setPixelColor(7,255,0,0);
    strip.setPixelColor(6,255,0,0);
    strip.setPixelColor(5,right[2]-512,0,767-right[2]);
    strip.setPixelColor(4,0,0,0);
  }
  else if (right[2] < 1023)
  {
    strip.setPixelColor(7,255,0,0);
    strip.setPixelColor(6,255,0,0);
    strip.setPixelColor(5,255,0,0);
    strip.setPixelColor(4,right[2]-768,0,1023-right[2]);
  }


  if (right[1] < 255)
  {
    strip.setPixelColor(0,right[1],0,255-right[1]);
    strip.setPixelColor(1,0,0,0);
    strip.setPixelColor(2,0,0,0);
    strip.setPixelColor(3,0,0,0);
  }
  else if (right[1] < 551)
  {
    strip.setPixelColor(0,255,0,0);
    strip.setPixelColor(1,right[1]-256,0,511-right[1]);
    strip.setPixelColor(2,0,0,0);
    strip.setPixelColor(3,0,0,0);
  }
  else if (right[1] < 767)
  {
    strip.setPixelColor(0,255,0,0);
    strip.setPixelColor(1,255,0,0);
    strip.setPixelColor(2,right[1]-512,0,767-right[1]);
    strip.setPixelColor(3,0,0,0);
  }
  else if (right[1] < 1023)
  {
    strip.setPixelColor(0,255,0,0);
    strip.setPixelColor(1,255,0,0);
    strip.setPixelColor(2,255,0,0);
    strip.setPixelColor(3,right[1]-768,0,1023-right[1]);
  }
  strip.show();
}

Currently I am adapting my 40 pixel code to 78 pixels so some stuff is not coded in yet. I am also probably not the neatest or most efficient programmer so keep that in mind.

Code: Select all

desklights:40: error: call of overloaded 'Adafruit_WS2801(int, int&, int&, int)' is ambiguous
C:\Users\onyex\Documents\! Projects\arduino-1.0.5-r2\libraries\WS2801/Adafruit_WS2801.h:25: note: candidates are: Adafruit_WS2801::Adafruit_WS2801(uint16_t, uint16_t, uint8_t, uint8_t, uint8_t)
C:\Users\onyex\Documents\! Projects\arduino-1.0.5-r2\libraries\WS2801/Adafruit_WS2801.h:24: note:                 Adafruit_WS2801::Adafruit_WS2801(uint16_t, uint8_t, uint8_t, uint8_t)
desklights:41: error: redefinition of 'Adafruit_WS2801 strip'
desklights:40: error: 'Adafruit_WS2801 strip' previously declared here
That is what comes out after attempting to compile.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: WS2801 36mm LED Pixel R and G Switched

Post by pburgess »

Declare the pins as type uint8_t instead of int:

Code: Select all

uint8_t dataPinLED  = 2,
        clockPinLED = 3;
You then have two declarations for 'strip' -- will need to delete or comment out one or the other.

This still won't address the issue of the two sets of LEDs having a different color order; the library can handle either type, but not a mix. You might need to tweak the library to check the pixel index and swap red & green in the appropriate cases.

User avatar
onyex
 
Posts: 6
Joined: Mon Aug 11, 2014 12:14 pm

Re: WS2801 36mm LED Pixel R and G Switched

Post by onyex »

Ok, the code compiles now but the strips look like this http://i.imgur.com/ZhAVZs4.jpg when plugged in and told to turn green. They flash to random colors and I don't even know where to begin to trouble shoot this.

On the note of the green/red issue, I found this:
The Connection and Driving of Cascading Operation

The transmit the data over long distance by cascading, the WS2801 integrates push-pull output stage with strong driving capability which enables the data and clock can be transmitted up to 6 meters at 2MHz clock frequency. To prevent the reflection, it is necessary to connect a 50Ω resistor at the data input or output port for impedance match.
This was in the WS2801 datasheet. Could this be the cause of the red and green switch?

Current code:

Code: Select all

//Credit to Ben Moyes in regards to spectrum analizer
//Credit to Laurid Meyer in regards to the Android code and ethernet code
//Credit to David Kavanagh in regards to the Adafruit LED cubes
//Credit to Mike LaGrasta for origional concept and some origional code
//Light table developed by Joe O'Connor
#include <SPI.h>
#include <Ethernet.h>
#include <Adafruit_WS2801.h>

//Set a MAC address for the ethernet Arduino  eg. DE:AD:BE:EF:FE:EE
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xEE };
//Set the IP address for the ethernet Arduino  eg. 192.168.1.105
IPAddress serverIP(192,168,1,105);
//Set the port for the ethernet Arduino to communicate through  eg. 8888
int serverPort = 8888;

//Spectrum Constants
int strobe = 4, // strobe pins on digital 4
    res = 5, // reset pins on digital 5
    left[7], // store band values in these arrays
    right[7],
    band=0;

//LED Constants
uint8_t dataPinLED = 2,
        clockPinLED = 3;

int red_Slider=0,
    green_Slider=0,
    blue_Slider=0;

char key[8];
int keyset = 0;

int audioFlag = 0;

//String queue where commands are stored in order
String commandStr = "";

//Initialize strip 
  Adafruit_WS2801 strip = Adafruit_WS2801(78, dataPinLED, clockPinLED, WS2801_GRB);


//Set default patern
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int defaultPattern = 9;/////////////////////////////////////////////////////////////////// change pattern here
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Test patern flag variable
bool defaultTestPattern = false;

// Initialize the Ethernet server library
// with the IP address and port you want to use 
EthernetServer server(serverPort);

void setup()
{
  
  //begin serial
  Serial.begin(9600);
  //Start the ethernet server
  Ethernet.begin(mac,serverIP);
  server.begin();
  Serial.println(" ----- Server has started ----- ");
  strip.begin();
  Serial.println(" ---- Light strips started ---- ");
  pinMode(res, OUTPUT); // reset
  pinMode(strobe, OUTPUT); // strobe
  digitalWrite(res,LOW); // reset low
  digitalWrite(strobe,HIGH); //pin 5 is RESET on the shield
  while(defaultTestPattern)
  {
    lightTest();
  }
}

void loop()
{
  //Listen for client
  EthernetClient client = server.available();
  if (client)//if connected
  {
    while (client.connected())//if the client is connected
    {
      readMSGEQ7();
      if(client.available())//if client is available
      {
        //reads the inputs from the client
        char c = client.read();
        //concatonates the commands into a string
        commandStr += c;
        if (c == '\n') //if new line, complete command
        {
          Serial.println(commandStr); //outputs a single command line
          if (commandStr.indexOf("RGB Slider: ") == 0) //if the command begins with set (yes, I know you shouldn't compare strings like that)
          {
            audioFlag = 0;
            String value = commandStr; //store the command into a new String
            value.replace("RGB Slider: ", ""); //removes set from the string and replaces it with a space
            Serial.println(value);
            tokenizeRGB(value);
            colorAll(Color(red_Slider, green_Slider, blue_Slider));
          }
          if (commandStr.indexOf("Audio") == 0) //if the command begins with set (yes, I know you shouldn't compare strings like that)
          {
            audioFlag = 1;
            Serial.print("Flag: ");
            Serial.print(audioFlag);
          }
          commandStr = ""; //resets the command queue
        }
      }
      if ( audioFlag == 1)
      {
        BANNED();
        strip.show();
      }
    }
    //Woh, slow down there. You gotta give time for the data to send
    delay(1);
    //close the connection
    client.stop();
  }
  else 
  {
    switch(defaultPattern) 
    {
      case (1):
        p_rainbow();
        break;
      case (2):
        p_cylon();
        break;
      case (3):
        p_random(0);
        break;
      case (4):
        colorLines();
        break;
      case (5):
        lightChaser();
        break;
      case (6):
        p_christmascolors();
        break;
      case (7):
        p_winterwonderland();
        break;
      case (8):
        timedpatten();
        break;
      case (9):
        p_solidgreen();
        break;
    }
  }
}

void timedpatten()
{
  int multiplier = 1;
  int time = millis()/(300000 * multiplier);
  if (time >= 5)
  {
    multiplier++;
    time = 0;
  }
  if (time == 0)
  {
    p_rainbow();
  }
  else if (time == 1)
  {
    p_random(5);
  }
  else if (time == 2)
  {
    colorLines();
  }
  else if (time == 3)
  {
    lightChaser();
  }
  else if (time == 4)
  {
    p_cylon();
  }
}

void BANNED()
{
  Serial.print("Left: ");
  for (band = 0; band < 7; band++)
  {
    Serial.print(left[band]);
    Serial.print(" ");
  }
  Serial.println();
  // display values of right channel on serial monitor
  Serial.print("Right: ");
  for (band = 0; band < 7; band++)
  {
    Serial.print(right[band]);
    Serial.print(" ");
  }
  Serial.println();
  Serial.println();
  
  lightOrgan();
}

void readMSGEQ7() // Function to read 7 band equalizers
{
  digitalWrite(res, HIGH);
  digitalWrite(res, LOW);
  for (band = 0; band < 7; band++)
  {
    digitalWrite(strobe,LOW); // strobe pin on the shield - kicks the IC up to the next band 
    delayMicroseconds(30); // 
    left[band] = analogRead(0); // store left band reading
    right[band] = analogRead(1); // ... and the right
    digitalWrite(strobe,HIGH); 
  }
}

void tokenizeRGB (String value)
{ 
  String temp = "";
  int i = 0;
  while (value.charAt(i) != ' ')
  {
    temp += value.charAt(i);
    i++;
  }
  temp += value.charAt(i+1);
  red_Slider = convertToInt(temp);

  i = i+1;
  temp = "";
  while (value.charAt(i) != ' ')
  {
    temp += value.charAt(i);
    i++;
  }
  temp += value.charAt(i+1);
  green_Slider = convertToInt(temp);

  i = i+1;
  temp = "";
  while (value.charAt(i) != '\n')
  {
    temp += value.charAt(i);
    i++;
  }
  temp += value.charAt(i+1);
  blue_Slider = convertToInt(temp);

  Serial.println(red_Slider);
  Serial.println(green_Slider);
  Serial.println(blue_Slider);
}

int convertToInt(String value)
{
  char buf[value.length()];
  value.toCharArray(buf,value.length());
  return atoi(buf);
}

// ascii hex to rgb
// in is a RGB hex color string "ff00ff"
// out is a 3 cell int array in which to store the result
// this is NOT a fast function, use it sparingly and not in tight loops
void ah2rgb(char * in, int * out) 
{
  char hr[3];
  char hg[3];
  char hb[3];
  hr[0] = in[0];
  hr[1] = in[1];
  hr[2] = 0;
  hg[0] = in[2];
  hg[1] = in[3];
  hg[2] = 0;
  hb[0] = in[4];
  hb[1] = in[5];
  hb[2] = 0;

  out[0] = (int) strtol(hr, NULL, 16);
  out[1] = (int) strtol(hg, NULL, 16);
  out[2] = (int) strtol(hb, NULL, 16);
}

// ascii hex to "Color", much faster
uint32_t ah2c(char * in) 
{
  int rgb[3];
  ah2rgb(in, rgb);
  return Color(rgb[0], rgb[1], rgb[2]);
}

// this takes x/y coordinates and maps it to a pixel offset
// just for ease of making patterns
int g2p(int x, int y) 
{
  int grid[6][13] = 
   {{72,71,60,59,48,47,36,35,24,23,12,11, 0}
   ,{73,70,61,58,49,46,37,34,25,22,13,10, 1}
   ,{74,69,62,57,50,45,38,33,26,21,14, 9, 2}
   ,{75,68,63,56,51,44,39,32,27,20,15, 8, 3}
   ,{76,67,64,55,52,43,40,31,28,19,16, 7, 4}
   ,{77,66,65,54,53,42,41,30,29,18,17, 6, 5}
  };
  return grid[y][x];
}

// fade from off to "target" rgb values (currently un-used, not well tested but should be right)
void off2rgb(int tr, int tg, int tb) 
{
  colorAll(Color(0,0,0));
  int r = 0;
  int g = 0;
  int b = 0;
  while (r < tr | g < tg | b < tb) {
    if (r < tr) 
    { 
      r++; 
    }
    if (g < tg) 
    { 
      g++; 
    }
    if (b < tb) 
    { 
      b++; 
    }
    colorAll(Color(r,g,b));
  }
}

// fade from rgb color to off
void rgb2off(int r, int g, int b) 
{
  while ( r > 0 | g > 0 | b > 0) 
  {
    if (r > 0) 
    { 
      r--; 
    }
    if (g > 0) 
    { 
      g--; 
    }
    if (b > 0) 
    { 
      b--; 
    }
    colorAll(Color(r,g,b));
  }
}

// set all pixels to a "Color" value
void colorAll(uint32_t c) 
{
  int i;
  for (i=0; i < strip.numPixels(); i++) 
  {
    strip.setPixelColor(i, c);
  }
  strip.show();
}

// set all pixels to a "Color" value, one at a time, with a delay
void colorWipe(uint32_t c, uint8_t wait) 
{
  int i;
  for (i=0; i < strip.numPixels(); i++) 
  {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

// create the "Color" value from RBG, Adafruit code
uint32_t Color(byte r, byte g, byte b) 
{
  // Create a 24 bit color value from R,G,B
  uint32_t c;
  c = r;
  c <<= 8;
  c |= g;
  c <<= 8;
  c |= b;
  return c;
}

//Input a value 0 to 255 to get a color value.
//The colours are a transition r - g -b - back to r
uint32_t Wheel(byte WheelPos)
{
  if (WheelPos < 85) 
  {
    return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } 
  else if (WheelPos < 170) 
  {
    WheelPos -= 85;
    return Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  else 
  {
    WheelPos -= 170; 
    return Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

/************** PATTERNS ****************/

void p_christmascolors()
{
  int i = random(0,2);

  switch (i)
  {
    case(0):

    strip.setPixelColor(random(0,strip.numPixels()), Color(255,0,0));
    strip.show();
    break;

    case (1):

    strip.setPixelColor(random(0,strip.numPixels()), Color(0,255,0));
    strip.show();
    break;

  }
  delay (20);
}


void p_winterwonderland()
{
  int i = random(0,2);

  switch (i)
  {
    case(0):

    strip.setPixelColor(random(0,strip.numPixels()), Color(0,0,255));
    strip.show();
    break;

    case (1):

    strip.setPixelColor(random(0,strip.numPixels()), Color(255,255,255));
    strip.show();
    break;
  }
  delay (20);
}

void p_solidgreen ()
{
  for (int i=0;i<78;i++)
  {
    strip.setPixelColor(i,0,255,0);
  }
  strip.show();
}

// random pixel, random color
void p_random (int wait) 
{
  strip.setPixelColor(random(0, strip.numPixels()),Color(random(0,255), random(0,255), random(0,255)));
  strip.show();
  delay(wait);
}

// RAINBOW TABLE
void p_rainbow() 
{
  int i, j;
  for (j=0; j < 256; j++) 
  {
    for (i=0; i < strip.numPixels(); i++) 
    {
      strip.setPixelColor(i, Wheel( ((i * 256 / strip.numPixels()) + j) % 256) );
    }  
    strip.show();
  }
}

// sweeping red lights with a trail (needs fixing)
void p_cylon() 
{
  uint32_t colors[4] = {Color(255,0,0), Color(150,0,0), Color(50,0,0), Color(0,0,0)};
  int wait = 100;
  int i;
  int j;
  for (i=0; i<13; i++) 
  {
    for (j=0; j<4; j++) 
    {
      int x = i-j;
      if (x < 40) 
      {
        strip.setPixelColor(g2p(x,0), colors[j]);
        strip.setPixelColor(g2p(x,1), colors[j]);
        strip.setPixelColor(g2p(x,2), colors[j]);
        strip.setPixelColor(g2p(x,3), colors[j]);
      }
    }
    strip.show();
    delay(wait);
  }
  for (i=10; i>-3; i--) 
  {
    for (j=0; j<4; j++) 
    {
      int x = i+j;
      if (x < 40) 
      { // max x value, ought to be a var
        strip.setPixelColor(g2p(i+j,0), colors[j]);
        strip.setPixelColor(g2p(i+j,1), colors[j]);
        strip.setPixelColor(g2p(i+j,2), colors[j]);
        strip.setPixelColor(g2p(i+j,3), colors[j]);
      }
    }
    strip.show();
    delay(wait);
  }
}

// Additional possibility. Initial code for visual equalizer
void colorLines() 
{
  int i;
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,0), Color(255,0,0));
  }
  strip.show();
  delay(500);
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,1), Color(0,255,0));
  }
  strip.show();
  delay(500);
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,2), Color(0,0,255));
  }
  strip.show();
  delay(500);
  for (i=0; i<10; i++) 
  {
    strip.setPixelColor(g2p(i,3), Color(255,255,255));
  }
  strip.show();
  delay(500);
  colorWipe(Color(0, 0, 0), 50);
}

// sweep all color extremes through all pixels (to find off color pixels)
void lightTest() 
{
  colorWipe(Color(255, 0, 0), 50);
  colorWipe(Color(0, 255, 0), 50);
  colorWipe(Color(0, 0, 255), 50);
  colorWipe(Color(255, 255, 255), 50);
  colorWipe(Color(0, 0, 0), 50);
}

// Random lights. Could do better with the coding but I got lazy.
void lightChaser() 
{
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
  colorWipe(Color(random(0,255), random(0,255), random(0,255)), 50);
}


void lightOrgan()
{
  if (left[1] < 255)
  {
    strip.setPixelColor(39,left[1],0,255-left[1]);
    strip.setPixelColor(38,0,0,0);
    strip.setPixelColor(37,0,0,0);
    strip.setPixelColor(36,0,0,0);
  }
  else if (left[1] < 551)
  {
    strip.setPixelColor(39,255,0,0);
    strip.setPixelColor(38,left[1]-256,0,511-left[1]);
    strip.setPixelColor(37,0,0,0);
    strip.setPixelColor(36,0,0,0);
  }
  else if (left[1] < 767)
  {
    strip.setPixelColor(39,255,0,0);
    strip.setPixelColor(38,255,0,0);
    strip.setPixelColor(37,left[1]-512,0,767-left[1]);
    strip.setPixelColor(36,0,0,0);
  }
  else if (left[1] < 1023)
  {
    strip.setPixelColor(39,255,0,0);
    strip.setPixelColor(38,255,0,0);
    strip.setPixelColor(37,255,0,0);
    strip.setPixelColor(36,left[1]-768,0,1023-left[1]);
  }


  if (left[2] < 255)
  {
    strip.setPixelColor(32,left[2],0,255-left[2]);
    strip.setPixelColor(33,0,0,0);
    strip.setPixelColor(34,0,0,0);
    strip.setPixelColor(35,0,0,0);
  }
  else if (left[2] < 551)
  {
    strip.setPixelColor(32,255,0,0);
    strip.setPixelColor(33,left[2]-256,0,511-left[2]);
    strip.setPixelColor(34,0,0,0);
    strip.setPixelColor(35,0,0,0);
  }
  else if (left[2] < 767)
  {
    strip.setPixelColor(32,255,0,0);
    strip.setPixelColor(33,255,0,0);
    strip.setPixelColor(34,left[2]-512,0,767-left[2]);
    strip.setPixelColor(35,0,0,0);
  }
  else if (left[2] < 1023)
  {
    strip.setPixelColor(32,255,0,0);
    strip.setPixelColor(33,255,0,0);
    strip.setPixelColor(34,255,0,0);
    strip.setPixelColor(35,left[2]-768,0,1023-left[2]);
  }


  if (left[3] < 255)
  {
    strip.setPixelColor(31,left[3],0,255-left[3]);
    strip.setPixelColor(30,0,0,0);
    strip.setPixelColor(29,0,0,0);
    strip.setPixelColor(28,0,0,0);
  }
  else if (left[3] < 551)
  {
    strip.setPixelColor(31,255,0,0);
    strip.setPixelColor(30,left[3]-256,0,511-left[3]);
    strip.setPixelColor(29,0,0,0);
    strip.setPixelColor(28,0,0,0);
  }
  else if (left[3] < 767)
  {
    strip.setPixelColor(31,255,0,0);
    strip.setPixelColor(30,255,0,0);
    strip.setPixelColor(29,left[3]-512,0,767-left[3]);
    strip.setPixelColor(28,0,0,0);
  }
  else if (left[3] < 1023)
  {
    strip.setPixelColor(31,255,0,0);
    strip.setPixelColor(30,255,0,0);
    strip.setPixelColor(29,255,0,0);
    strip.setPixelColor(28,left[3]-768,0,1023-left[3]);
  }


  if (left[4] < 255)
  {
    strip.setPixelColor(24,left[4],0,255-left[4]);
    strip.setPixelColor(25,0,0,0);
    strip.setPixelColor(26,0,0,0);
    strip.setPixelColor(27,0,0,0);
  }
  else if (left[4] < 551)
  {
    strip.setPixelColor(24,255,0,0);
    strip.setPixelColor(25,left[4]-256,0,511-left[4]);
    strip.setPixelColor(26,0,0,0);
    strip.setPixelColor(27,0,0,0);
  }
  else if (left[4] < 767)
  {
    strip.setPixelColor(24,255,0,0);
    strip.setPixelColor(25,255,0,0);
    strip.setPixelColor(26,left[4]-512,0,767-left[4]);
    strip.setPixelColor(27,0,0,0);
  }
  else if (left[4] < 1023)
  {
    strip.setPixelColor(24,255,0,0);
    strip.setPixelColor(25,255,0,0);
    strip.setPixelColor(26,255,0,0);
    strip.setPixelColor(27,left[4]-768,0,1023-left[4]);
  }


  if (left[5] < 255)
  {
    strip.setPixelColor(23,left[5],0,255-left[5]);
    strip.setPixelColor(22,0,0,0);
    strip.setPixelColor(21,0,0,0);
    strip.setPixelColor(20,0,0,0);
  }
  else if (left[5] < 551)
  {
    strip.setPixelColor(23,255,0,0);
    strip.setPixelColor(22,left[5]-256,0,511-left[5]);
    strip.setPixelColor(21,0,0,0);
    strip.setPixelColor(20,0,0,0);
  }
  else if (left[5] < 767)
  {
    strip.setPixelColor(23,255,0,0);
    strip.setPixelColor(22,255,0,0);
    strip.setPixelColor(21,left[5]-512,0,767-left[5]);
    strip.setPixelColor(20,0,0,0);
  }
  else if (left[5] < 1023)
  {
    strip.setPixelColor(23,255,0,0);
    strip.setPixelColor(22,255,0,0);
    strip.setPixelColor(21,255,0,0);
    strip.setPixelColor(20,left[5]-768,0,1023-left[5]);
  }


  if (right[5] < 255)
  {
    strip.setPixelColor(16,right[5],0,255-right[5]);
    strip.setPixelColor(17,0,0,0);
    strip.setPixelColor(18,0,0,0);
    strip.setPixelColor(19,0,0,0);
  }
  else if (right[5] < 551)
  {
    strip.setPixelColor(16,255,0,0);
    strip.setPixelColor(17,right[5]-256,0,511-right[5]);
    strip.setPixelColor(18,0,0,0);
    strip.setPixelColor(19,0,0,0);
  }
  else if (right[5] < 767)
  {
    strip.setPixelColor(16,255,0,0);
    strip.setPixelColor(17,255,0,0);
    strip.setPixelColor(18,right[5]-512,0,767-right[5]);
    strip.setPixelColor(19,0,0,0);
  }
  else if (right[5] < 1023)
  {
    strip.setPixelColor(16,255,0,0);
    strip.setPixelColor(17,255,0,0);
    strip.setPixelColor(18,255,0,0);
    strip.setPixelColor(19,right[5]-768,0,1023-right[5]);
  }


  if (right[4] < 255)
  {
    strip.setPixelColor(15,right[4],0,255-right[4]);
    strip.setPixelColor(14,0,0,0);
    strip.setPixelColor(13,0,0,0);
    strip.setPixelColor(12,0,0,0);
  }
  else if (right[4] < 551)
  {
    strip.setPixelColor(15,255,0,0);
    strip.setPixelColor(14,right[4]-256,0,511-right[4]);
    strip.setPixelColor(13,0,0,0);
    strip.setPixelColor(12,0,0,0);
  }
  else if (right[4] < 767)
  {
    strip.setPixelColor(15,255,0,0);
    strip.setPixelColor(14,255,0,0);
    strip.setPixelColor(13,right[4]-512,0,767-right[4]);
    strip.setPixelColor(12,0,0,0);
  }
  else if (right[4] < 1023)
  {
    strip.setPixelColor(15,255,0,0);
    strip.setPixelColor(14,255,0,0);
    strip.setPixelColor(13,255,0,0);
    strip.setPixelColor(12,right[4]-768,0,1023-right[4]);
  }


  if (right[3] < 255)
  {
    strip.setPixelColor(8,right[3],0,255-right[3]);
    strip.setPixelColor(9,0,0,0);
    strip.setPixelColor(10,0,0,0);
    strip.setPixelColor(11,0,0,0);
  }
  else if (right[3] < 551)
  {
    strip.setPixelColor(8,255,0,0);
    strip.setPixelColor(9,right[3]-256,0,511-right[3]);
    strip.setPixelColor(10,0,0,0);
    strip.setPixelColor(11,0,0,0);
  }
  else if (right[3] < 767)
  {
    strip.setPixelColor(8,255,0,0);
    strip.setPixelColor(9,255,0,0);
    strip.setPixelColor(10,right[3]-512,0,767-right[3]);
    strip.setPixelColor(11,0,0,0);
  }
  else if (right[3] < 1023)
  {
    strip.setPixelColor(8,255,0,0);
    strip.setPixelColor(9,255,0,0);
    strip.setPixelColor(10,255,0,0);
    strip.setPixelColor(11,right[3]-768,0,1023-right[3]);
  }


  if (right[2] < 255)
  {
    strip.setPixelColor(7,right[2],0,255-right[2]);
    strip.setPixelColor(6,0,0,0);
    strip.setPixelColor(5,0,0,0);
    strip.setPixelColor(4,0,0,0);
  }
  else if (right[2] < 551)
  {
    strip.setPixelColor(7,255,0,0);
    strip.setPixelColor(6,right[2]-256,0,511-right[2]);
    strip.setPixelColor(5,0,0,0);
    strip.setPixelColor(4,0,0,0);
  }
  else if (right[2] < 767)
  {
    strip.setPixelColor(7,255,0,0);
    strip.setPixelColor(6,255,0,0);
    strip.setPixelColor(5,right[2]-512,0,767-right[2]);
    strip.setPixelColor(4,0,0,0);
  }
  else if (right[2] < 1023)
  {
    strip.setPixelColor(7,255,0,0);
    strip.setPixelColor(6,255,0,0);
    strip.setPixelColor(5,255,0,0);
    strip.setPixelColor(4,right[2]-768,0,1023-right[2]);
  }


  if (right[1] < 255)
  {
    strip.setPixelColor(0,right[1],0,255-right[1]);
    strip.setPixelColor(1,0,0,0);
    strip.setPixelColor(2,0,0,0);
    strip.setPixelColor(3,0,0,0);
  }
  else if (right[1] < 551)
  {
    strip.setPixelColor(0,255,0,0);
    strip.setPixelColor(1,right[1]-256,0,511-right[1]);
    strip.setPixelColor(2,0,0,0);
    strip.setPixelColor(3,0,0,0);
  }
  else if (right[1] < 767)
  {
    strip.setPixelColor(0,255,0,0);
    strip.setPixelColor(1,255,0,0);
    strip.setPixelColor(2,right[1]-512,0,767-right[1]);
    strip.setPixelColor(3,0,0,0);
  }
  else if (right[1] < 1023)
  {
    strip.setPixelColor(0,255,0,0);
    strip.setPixelColor(1,255,0,0);
    strip.setPixelColor(2,255,0,0);
    strip.setPixelColor(3,right[1]-768,0,1023-right[1]);
  }
  strip.show();
}


User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: WS2801 36mm LED Pixel R and G Switched

Post by pburgess »

Could you try the strandtest example, see if that works? Wondering if it might be a RAM space limitation; the Ethernet library is pretty hungry as I recall.

User avatar
onyex
 
Posts: 6
Joined: Mon Aug 11, 2014 12:14 pm

Re: WS2801 36mm LED Pixel R and G Switched

Post by onyex »

I found the issue, the ground wire wasn't connected properly.

However the green and red problem still exists.

Edit:
I made a mock up of the lights with two I cut off the end of the new strands. Both are red so it is not (probably) a reflection problem.

User avatar
pburgess
 
Posts: 4161
Joined: Sun Oct 26, 2008 2:29 am

Re: WS2801 36mm LED Pixel R and G Switched

Post by pburgess »

The factory must've changed the driver-to-LED wiring at some point in production between your first and second sets of LEDs.

You'll need to tweak the WS2801 library to work around this. Unfortunately if you have other WS2801 projects they'll run funny. But if this is the only one you use, then it might be an acceptable compromise. Only alternative is to replace the older LEDs to match the manufacturer's current RGB/GRB sequence. Or you could copy the library and change the class name for this one project. But I digress...

In Adafruit_WS2801.cpp, look for the method setPixelColor() (around line 216). A few lines down you should see this block of code:

Code: Select all

    if(rgb_order == WS2801_RGB) {
      *p++ = r;
      *p++ = g;
    } else {
      *p++ = g;
      *p++ = r;
    }
Change the first line of that block to:

Code: Select all

    if(n < 40) {
You'll see a similar thing around line 252. Make the same change there. And if you're using getPixelColor(), also change the test condition at line 284.

I hope that'll work well enough for your project. Unfortunately this sort of occurrence is a side effect of how these LEDs are sourced...the hobbyist market often gets the "end lots" following clients from the much larger digital signage industry. On the plus side, yay, affordable smart LEDs for hobbyists. Downside, very occasionally they change the wiring, plugs, color order, etc., and what's in inventory today won't always match what was there before.

User avatar
onyex
 
Posts: 6
Joined: Mon Aug 11, 2014 12:14 pm

Re: WS2801 36mm LED Pixel R and G Switched

Post by onyex »

I was afraid that I might have to do that. I ended up cloning the WS2801 library and changed the libraries name. For reference, the fix that worked was

Code: Select all

if(n>39)
at 216,252 and 284. It now works as it should. Thank you for the help!

User avatar
ReverZ
 
Posts: 1
Joined: Thu Sep 18, 2014 11:31 am

Re: WS2801 36mm LED Pixel R and G Switched

Post by ReverZ »

Good to know that it works now for you!
Just a question regarding your hardware setup: Did you connect just one end of the first strand with your power supply and connect the power wires of the other strands together? That ´s what I think to identify on one of the linked pictures.

Best Regards,
ReverZ

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”