ws2812 tape all evens one colour and odds another colour

Hi,

I have been trying to do a split on some ws2812 tape as in odds one colour and evens another colour. I have it working but can not get the colours to go to full as in 255.

Here is my code

#include <FastLED.h>

int inMin = 3; // Lowest input pin
int inMax = 12; // Highest input pin

int s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 = 0;

#define LED_PIN     2
#define NUM_LEDS    20

CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];
int s=0;
int z=0;

void setup() {

  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

  pinMode(A0,INPUT);
  pinMode(A1,INPUT);

  for(int i=inMin; i<=inMax; i++)
{
  pinMode(i, INPUT);
}
}

void loop(){

int u = NUM_LEDS;

 // IF s1 + s2 = Yellow, s1 + s3 = purple
 // IF s4 + s5 = Yellow, s4 + s6 = purple

  s1 = digitalRead(3); //RED
  s2 = digitalRead(4); //GREEN
  s3 = digitalRead(5); //BLUE
  s4 = digitalRead(6); //RED
  s5 = digitalRead(7); //GREEN
  s6 = digitalRead(8); //BLUE
  s7 = digitalRead(9);

   leds[u]= CRGB (s1, s2, s3);
   leds[u-1]= CRGB (s4, s5, s6);


for (int i = 0; i <= u; i++) 
   {
     leds[i] = leds[i+2];
   }
  
FastLED.show();
  
}

forgot to say this was something I was trying to do about a year ago or more.

From your description I believe it is a hardware problem. It sounds like you are using the Arduino as a power supply which it is NOT! Also you can't get this to operate from a USB connection, it requires well over 50 watts, closer to 90. Post a schematic, not a frizzy drawing showing all connections, power, ground, power supplies, and links therein.

I am only using 7 leds as a test when it connected to my laptop and I have checked to see if it was a power problem it was still the same when I ran it of a 3a 5v power supply.

I was trying other code but it set all the leds one colour as in they where all red or all what ever colour I set. I lost this code as when I deleted it to write the code above I though I had opened a file but I didn't.

I thinking it is something to do with the value of s1 ie when digitalRead is High it is = 1 and this is the value is been passed to s1.

I will post the schematic tomorrow at some point when I get time

but can not get the colours to go to full as in 255.

Do not know what that means.

I tested the below code using an Uno with a 10 pixel LED strip and an external 5V supply.

I have been trying to do a split on some ws2812 tape as in odds one colour and evens another colour.

How about like this?

#include <FastLED.h>

#define NUM_LEDS 10

CRGB leds[NUM_LEDS];

const byte DATA_PIN = 4;

void setup()
{
   Serial.begin(115200);
   LEDS.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
   LEDS.setBrightness(100);
}

void loop()
{
   altColors();
   FastLED.show();
}

void altColors()
{
   // evens one color
   for (int n = 0; n < NUM_LEDS; n += 2)
   {
      leds[n] = CRGB::Red;
   }

   // odds another color
   for (int n = 1; n < NUM_LEDS; n += 2)
   {
      leds[n] = CRGB::Blue;
   }
}

GroundFungus,

your code is something like I had before. I am trying to use dip switches to set the colors ie

Red = s1, Green = s2, blue =s3 this is for the odd leds and for the evens i red =s4, green = s5, blue =s6

Also if s1 and s2 is on = yellow

So I can change the colour with re doing the code.

Schematic?

Why do you have two LED arrays?

CRGB leds[NUM_LEDS];
CRGB led[NUM_LEDS];

The Arduino can't provide enough power for 20 LEDs.

And, as GroundFungus said, what does "go to full as in 255." mean?

for (int i = 0; i <= u; i++)
   {
     leds[i] = leds[i+2];
   }

Here you are anyway 'reading' beyond the size of the array (hey it's FastLED)

but can not get the colours to go to full as in 255.

well no you can't, you should multiply the result of digitalread() with 255 (or whatever brightness you want), as it is s1 - s7 are returning 0 or 1.

s1 = digitalRead(3); //RED
  s2 = digitalRead(4); //GREEN
  s3 = digitalRead(5); //BLUE
  s4 = digitalRead(6); //RED
  s5 = digitalRead(7); //GREEN
  s6 = digitalRead(8); //BLUE
  s7 = digitalRead(9);

   leds[u]= CRGB (s1, s2, s3);
   leds[u-1]= CRGB (s4, s5, s6);

Few other pointers

int inMin = 3; // Lowest input pin
int inMax = 12; // Highest input pin

int s1, s2, s3, s4, s5, s6, s7, s8, s9, s10 = 0;

you should use an array !

{
  pinMode(i, INPUT);
}

probably INPUT_PULLUP would be better, though without a schematic it is hard to say.

The Arduino can't provide enough power for 20 LEDs.

The Arduino can't no, but a USB port might be able to, if not enough power is provided, you will not see any of the LEDS light up simply because the chip will lack power. Best way to find out how much power your strip uses (the specs usually state an amount that is quite a bit above the actual requirements) is connect it to a source that is easily enough, make all LED's light up 'WHITE' and connect a Amp meter in between.

Thank you Deva_Rishi,

well no you can't, you should multiply the result of digitalread() with 255 (or whatever brightness you want), as it is s1 - s7 are returning 0 or 1.

I have it solved by something you said and I am kicking myself as I did not think think of it. I have added the multiply to my code to the digitalRead() and it work as I wanted. I was thinking I was missing something.

The Arduino can't no, but a USB port might be able to, if not enough power is provided, you will not see any of the LEDS light up simply because the chip will lack power. Best way to find out how much power your strip uses (the specs usually state an amount that is quite a bit above the actual requirements) is connect it to a source that is easily enough, make all LED's light up 'WHITE' and connect a Amp meter in between.

I am using a setup of 7 LEDs so I can get all power from the USB when doing my code. I do know what I am planing to power will take more than what USB can power. I am controlling 10 strings of 20 LEDs. I know my power supply is 5v 6amp and I have some head room for adding more LEDs if I need to.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.