How to reverse the direction of the LED strip by 180 degrees

That's a great looking project! You can be proud of it.

If I finally understand what you wanted to do, then it is not possible in software. The physical data input and output of the LED strip is something that is not changeable without completely remanufacturing the strip. The time to make the change would have been in the beginning while you could still decide how to arrange the strip.

I don't understand why it's so difficult to modify the code so that the LEDs are written in the required order with the strips in the desired physical orientation. Seems a better choice than trying to "reverse" then in software later.

@EmilyJane / @gfvalvo
So, do you think it would work to turn the LED strip upside down (in reverse) and change the direction in the code?
How would this work in the code?

But, so as not to give you any more "neuron burn", I'll leave it like that.

Yes, that's what everyone has been suggesting I think but it sounded like you didn't want to make that kind of change to your hardware.

1 Like

If it works, ship it.

I think everyone tried to say; The DATA signal must enter the DIN (DATA IN) side of the LED strip (see all the arrows). The strip can be in any physical orientation and can be programmed to do anything. I think we misinterpreted terms.

Here... have another clock idea...

@xfpd

Loving the 'darkClock', however there is a minor flaw, try

if (i == (now.hour()%12)*5 + (now.minute()/12))

Seems to work

1 Like

Nice clock!

See @PaulRB's suggestion in #10.

Carefully save a copy of your sketch what works now.

Use the IDE as directed in #10 to change every occurrence of writing a colour to a pixel.

Every time it once wrote to pixel 59, it will instead write to 0. 58's colour ends up in pixel 1. And so forth. Pixel N will be redirected to pixel 59 - N. It's a simple transformation and those show up alla time, not always to compensate for lack of planning.

Run the modified sketch in your existing clock… it will be upside down.

The number 59 and subtraction feature in a few of our suggestions… because your strip is 60 long. Fixing things in software isn't a bad thing; one might wonder where we'd be if it weren't possible.

And global search and replace won't take very long nor should it be too hard to see what the result is and why it works.

Nice clock!

a7

On reflection I'm not certain the search & replace will fix things perfectly. Might need to add some brackets.

For example

strip.setPixelColor(currentHour * 5 - 1, 0, 0, 0);

would become

strip.setPixelColor(59 - currentHour * 5 - 1, 0, 0, 0);

but needs to be, I think,

strip.setPixelColor(59 - (currentHour * 5 - 1), 0, 0, 0);

<3

Was I not making the 12 hours map to 60 pixels? (thank you... I see it now... hour pixels + minute pixels)

On reflection <- I see what you did there. :expressionless:

That may be why I didn't go down that path, and I swear that after reading your response I looked at all of them and thought it would be OK...

As a hacker, I'd prolly waste spend time trying to overload or macro my way out of this mess.

a7

I'm continuing, because you woke me up again!

You say to replace everything after the parentheses, like here:

strip2.setPixelColor(currentSecond, 0, 0, 0);

It would look like this:

strip2.setPixelColor(59 - currentSecond, 0, 0, 0);

And how would it look on lines 100 - 111; 114 - 116; and in others "setPixelColor" ?

Sorry, my knowledge is very little.

I will close this matter here. You have all been very kind in helping me; thank you very much and may God bless you all. :brazil:

Correct.

If the first parameter, which is the pixel number/position, contains a formula, put extra brackets around that formula. Then put "59 - " before the new brackets.

Does that mean you fixed it completely? If so, well done. If not, why are you giving up?

I too thought the towel had been thrown in.

Here's a hack that adds a reversed strip method. The final step is done with macros to perform the otherwise global search and replace.

The only good thing I can say about it is that the changes are very localized.

See it at

and the one line that undoes the hack, or reverses the reverse, is marked:

// Uncomment the following line for normal pixel order
# define setPixelColor setReversePixelColor

The code:

// https://wokwi.com/projects/427678668251091969

# include <Adafruit_NeoPixel.h>
# define NLEDS  64

class Hack : public Adafruit_NeoPixel {
public:
    // Properly calling the base class constructor using an initializer list
    Hack(int a, int b, int c) : Adafruit_NeoPixel(a, b, c) {}

    void setReversePixelColor(unsigned char thePixel, unsigned long theColor);
};

// Function to set the reverse pixel color
void Hack::setReversePixelColor(unsigned char thePixel, unsigned long theColor) {
  setPixelColor(numPixels() - thePixel - 1, theColor);
}

# define Adafruit_NeoPixel Hack

// Uncomment the following line for normal pixel order
# define setPixelColor setReversePixelColor


Hack strip(NLEDS, 6, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(115200);
  Serial.println("\nstrip reverse hack\n");

  strip.begin();  // Initialize the strip
  strip.setPixelColor(0, 0xff0000);  // Set some pixels to test
  strip.setPixelColor(1, 0x00ff00);
  strip.setPixelColor(2, 0x0000ff);
  strip.setPixelColor(63, 0xffffff);

  strip.show();  // Update the strip
  delay(777);
  strip.clear();  // Clear the strip after a short delay
}

void loop() {
  static byte traveller;

  strip.clear();  // Clear the strip at the start of each loop
  strip.setPixelColor(traveller & 0x3f, 0xff0000);  // Set a single pixel to red
  strip.show();  // Update the strip

  traveller++;  // Increment the traveller variable

  delay(166);  // Wait before updating again
}

I had a bit of trouble with some pesky syntax. I thought all methods from the base class would be available on a sort of "pass through" basis, but I found I was having to worry about a "missing" constructor. I wrote a passthourhg method for Hack, which turned the compiled sketch non-functional. No pixels. chatGPT was useful and slightly tweaked my code and added a few comments.

After, we had this final exchange

alto777:

Pesky syntax. I was on the right track, thanks for the help. BTW do you have an opinion about cowboy hackers like me, who fix things with kludges? It was just to expedite a temporary issue; it will not be part of the product.

chatGPT:

Haha, I get it—sometimes a little "hacky" solution is exactly what's needed, especially when you're on a tight deadline or need a quick workaround to get something functional. As a "cowboy hacker" (as you put it), you're probably skilled at getting things to work quickly, even if the solution might not win any style points. I think that kind of ingenuity is valuable in many contexts!

That said, it's also important to know when to step back and refactor that "kludge" into something cleaner, especially if the project grows or if others will be working with your code in the future. But in the heat of the moment, if it’s just to get something temporary working and it’ll be replaced or refactored later, there’s absolutely nothing wrong with a good old-fashioned hack.

In short: I admire the creativity and drive behind cowboy hacking as long as you’re mindful that it’s a temporary solution. It's like putting out a fire with a garden hose until you can bring in the fire trucks later. :wink:

If it works for now and gets you closer to your goal, you’re doing great! Just keep an eye on the bigger picture if it’s going to turn into something more long-term.

alto777:

THX CU

a7

Everything seems to be working. Right now, I'm leaving the strip on to see if everything is behaving normally.

Here's what was changed, according to PaulRB's valuable tip:

This:

strip.setPixelColor(currentSecond - 1 , 0, 0, 0);
strip.setPixelColor(currentSecond, 0, 0, 0);
strip.setPixelColor(currentMinute, 0, 0, 0);
strip.setPixelColor(currentHour * 5 - 1, 0, 0, 0);
strip.setPixelColor(currentHour * 5, 0, 0, 0);
strip.setPixelColor(currentHour * 5 + 1, 0, 0, 0);
strip.show();

For this:

strip.setPixelColor(59 - currentSecond, 0, 0, 0);
strip.setPixelColor(59 - currentMinute, 0, 0, 0);
strip.setPixelColor(59 - (currentHour * 5 - 1), 0, 0, 0);
strip.setPixelColor(59 - (currentHour * 5), 0, 0, 0);
strip.setPixelColor(59 - (currentHour * 5 + 1), 0, 0, 0);
strip.show();

And I had to change this:

      strip.setPixelColor(zero, 125, 125, 125);
      strip.setPixelColor(five, 10, 10, 10);
      strip.setPixelColor(ten, 10, 10, 10);
      strip.setPixelColor(fifteen, 125, 125, 125);
      strip.setPixelColor(twenty, 10, 10, 10);
      strip.setPixelColor(twentyfive, 10, 10, 10);
      strip.setPixelColor(therty, 125, 125, 125);
      strip.setPixelColor(thertyfive, 10, 10, 10);
      strip.setPixelColor(fourty, 10, 10, 10);
      strip.setPixelColor(fourtyfive, 125, 125, 125);
      strip.setPixelColor(fifty, 10, 10, 10);
      strip.setPixelColor(fiftyfive, 10, 10, 10);

For this:

      strip.setPixelColor(59, 125, 125, 125);
      strip.setPixelColor(4, 10, 10, 10);
      strip.setPixelColor(9, 10, 10, 10);
      strip.setPixelColor(14, 125, 125, 125);
      strip.setPixelColor(19, 10, 10, 10);
      strip.setPixelColor(24, 10, 10, 10);
      strip.setPixelColor(29, 125, 125, 125);
      strip.setPixelColor(34, 10, 10, 10);
      strip.setPixelColor(39, 10, 10, 10);
      strip.setPixelColor(44, 125, 125, 125);
      strip.setPixelColor(49, 10, 10, 10);
      strip.setPixelColor(54, 10, 10, 10);

The latter are the Pixels that represent the 5-minute marks on the clock.

I am immensely grateful to everyone who helped me, especially PaulRB's tip.

If anything happens, I'll get back to you.

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