octoWS2811 and using unused strip pins.

orac

Active member
I have been playing with a little project that is now needing a little more urgency.
With some testing I found that the octoWS2911 library gave the best results for a single strip of LEDs. The next stage of the project was to attach a basic LCD, which I did only to be greated with all sorts on the display.
Eventually realising what the issue maybe i moved the LCD connections around. While finding this out i found that the FastLED has a similar issue (it also crashed during my programme - I have yet to fully investigate why)
With that in mind is it possible to use the pins used for other LED strip for thing other than LED strips? I only have to add a rotary encoder so pin count should not be an issue, but I am curious.
I did not see anything specifically on using less than 8 strips.


This is running on a teensy 3.2, still very much a work in progress.
Code:
#include <OctoWS2811.h>
#include <LiquidCrystal.h>

//const int rs = 14, en = 15, d4 = 16, d5 = 17, d6 = 18, d7 = 19;
//const int rs = 12, en = 11, d4 = 10, d5 = 9, d6 = 8, d7 = 7;
const int rs = 10, en = 11, d4 = 18, d5 = 17, d6 = 16, d7 = 15;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

const int ledsPerStrip = 216;         //one strip of 216
DMAMEM int displayMemory[ledsPerStrip*6];
int drawingMemory[ledsPerStrip*6];

const int config = WS2811_GRB | WS2811_800kHz;
OctoWS2811 pixels(ledsPerStrip, displayMemory, drawingMemory, config);

//upper case R,G,B set the colour
uint16_t R = 255;
uint16_t B = 0;
uint16_t G = 0;
//lower case r,g,b is manipulated but the bright function and should not be manually
//these are to allow brightness control
byte r;
byte g;
byte b;

#define bright_var A9
byte Brightness = 65;
int new_bright = 0;
byte old_bright = 0;
int upHyst_bright = 0;
int loHyst_bright = 0;

uint16_t i = 0;
uint16_t j = 0;

byte q = 0;

byte bottom_ring = 0;    //this is the only set of LED at are access in sequence
byte lower_riser[] =  { 36,  99, 117, 152,  62, 80};    //six lower risers - 3 up, 3 down
byte middle_ring[] =  { 45,  63, 108, 135};             //middle ring only has 4 address
byte upper_riser[] =  {153, 126,  81, 207, 206, 98};    //six upper risers - 4 up, 2 down
byte top_ring[] =     {162, 171, 180, 189};             //top ring only has 4 addresses

byte pattern_1[] = {1,21,2,20,3,19,4,18,5,17,6,16,7,15,8,14,9,13,10,12,11};
byte pattern_2[] = {11,10,12,9,13,8,14,7,15,6,16,5,17,4,18,3,19,2,20,1,21};

#define DELAYVAL 0

void setup() {
  pinMode(bright_var, INPUT);
  pinMode(rs, OUTPUT);
  pinMode(en, OUTPUT);
  pinMode(d4, OUTPUT);
  pinMode(d5, OUTPUT);
  pinMode(d6, OUTPUT);
  pinMode(d7, OUTPUT);  

  Serial.begin(115200);
  delay(1000);
  Serial.println("Starting");
  pixels.begin();
  set_bright();       //use this to allow for brightness control instead of pixels.show()
  lcd.begin(16,2);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Running");
}

void loop() {
   //use this for smooth colour circle
  for (j = 0; j < 255; j++){
    for (byte i = 0; i < 22; i++){
      Wheel((i+j) & 255);
      set_Leds(i);
      change_bright();    //see if brightness has been changed
      set_bright();     //this contain pixels.show
      //pixels.show();      //using pixels.show seem to cause issues - don't call this and LCD is fine
                            //call this and LCD show carbage and seem to overflow each line
                            //only when using pin in relation to octoWS2811 for LCD
    }
   }
    
    /*
    //use this for brutal colour pattern - testing pattern arrays
    for (i = 1; i < 22; i++){
      q = pattern_2[i-1];
      set_bright();
      set_Leds(q);
      delay(DELAYVAL);
      if (R == 255){
        R = 0;
        B = 255;
      }else if (B == 255){
        B = 0;
        G = 255;
      }else{
        G = 0;
        R = 255;
      }
    }
    if (R == 255){
      R = 0;
      B = 255;
    }else if (B == 255){
      B = 0;
      G = 255;
    }else{
      G = 0;
      R = 255;
    }
    */
}

void change_bright(){
  new_bright = analogRead(bright_var);
  if (new_bright < loHyst_bright || new_bright > upHyst_bright){
    Serial.print("Brightness Changed: ");
    Serial.println(new_bright);
    Brightness = map(new_bright, 0, 1023, 10, 255);
    lcd.setCursor(0,1);
    lcd.print("     ");   //clear small section of display
    lcd.setCursor(0,1);
    lcd.print(Brightness);
    Serial.print("Brightness: ");
    Serial.println(Brightness);
    loHyst_bright = new_bright - 10;
    upHyst_bright = new_bright + 10;
  }
}

void set_Leds(byte No){
  byte mode = 0;
  if (No == 1)                  mode = 1;
  if ((No >= 2) && (No <= 10))  mode = 2;
  if (No == 11)                 mode = 3;
  if ((No >= 12) && (No <= 20)) mode = 4;
  if (No == 21)                 mode = 5;

  switch(mode){
    case 1 :
      for(byte n=0; n<36; n++) {
        pixels.setPixel(n,r,g,b);
      }
      break;
        
    case 2:
      for (byte n = 0; n < 3; n++){
        pixels.setPixel(lower_riser[n]-2+No,r,g,b);
      }
      for (byte n = 3; n < 6; n++){
        pixels.setPixel(lower_riser[n]+2-No,r,g,b);
      }
      break;
      
    case 3:
      for(byte n=0; n<9; n++){
        pixels.setPixel(middle_ring[0]+n,r,g,b);
        pixels.setPixel(middle_ring[1]+n,r,g,b);
        pixels.setPixel(middle_ring[2]+n,r,g,b);
        pixels.setPixel(middle_ring[3]+n,r,g,b);
      }      
      break;
      
    case 4:
      for (byte n = 0; n < 4; n++){
        pixels.setPixel(upper_riser[n]-12+No,r,g,b);
      }
      for (byte n = 4; n < 6; n++){
        pixels.setPixel(upper_riser[n]+12-No,r,g,b);
      }
      break;
      
    case 5:
      for(int n=0; n<9; n++){
        pixels.setPixel(top_ring[0]+n,r,g,b);
        pixels.setPixel(top_ring[1]+n,r,g,b);
        pixels.setPixel(top_ring[2]+n,r,g,b);
        pixels.setPixel(top_ring[3]+n,r,g,b);
      }
      break;
      
    default:
     break;
  }
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    R = 255 - WheelPos * 3;
    G = 0;
    B = WheelPos *3;
    //set_bright();
    return;
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    R = 0;
    G = WheelPos * 3;
    B = 255 - WheelPos * 3;
    //set_bright();
    return;
  }
  WheelPos -= 170;
  R = WheelPos *3;
  G = 255 - WheelPos * 3;
  B = 0;
  //set_bright();
  return;
}

void set_bright() {
      r = (R * Brightness) >> 8;
      g = (G * Brightness) >> 8;
      b = (B * Brightness) >> 8;
      pixels.show();
}
 
Back
Top