My leds stay on?

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
schumi2004
 
Posts: 5
Joined: Mon Jan 02, 2012 5:04 am

My leds stay on?

Post by schumi2004 »

Hi,

I'm pretty new to this but with the available tutorials i got my Arduino UNO R3 up and running with 50 leds.(WS2801)
I't's connected to my HTPC running XBMC with Boblight and all works as expected except for one thing.
When i pause a movie or serie the leds stay on and won't go off until i actually stop the movie.

Is there a way to modify LEDstream.pde in such a way it will turn of the leds after a periode of time?

I found someting in pde file that should do this but it doesn't seem to work

Code: Select all

// If no serial data is received for a while, the LEDs are shut off
// automatically.  This avoids the annoying "stuck pixel" look when
// quitting LED display programs on the host computer.
static const unsigned long serialTimeout = 15000; // 15 seconds
I don't have a clue on how to modify code so it will turn off when there is no change in picture.

Any ideas?

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: My leds stay on?

Post by adafruit_support_rick »

LEDStream.pde really has no way of knowing that the picture hasn't changed.

The timeout you found will turn the lights off if the arduino stops receiving data from the host computer. If you want the lights to turn off when the picture is paused, then the place to do that is in the host computer. I assume you would have to somehow modify Boblight.

User avatar
schumi2004
 
Posts: 5
Joined: Mon Jan 02, 2012 5:04 am

Re: My leds stay on?

Post by schumi2004 »

Someone hinted to make use of MODE_HOLD

Make buffer etc

Code: Select all

case MODE_HOLD: 
  If (OldBuffer == Buffer) 
  { 
       Oldbuffer = buffer; 
       if(timeout(t, nLEDs) == true)  
       {  
           return; 
       } 
  } 
  else 
  { 
    Oldbuffer = buffer; 
  }
But i couldn't get it added to my ledstream, there was already a case MODE_HOLD and didn't knew how to add it.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: My leds stay on?

Post by adafruit_support_rick »

What is supposed to go into this buffer?

User avatar
schumi2004
 
Posts: 5
Joined: Mon Jan 02, 2012 5:04 am

Re: My leds stay on?

Post by schumi2004 »

I think the current picture input.

If input doesn't change then shutdown leds.

User avatar
adafruit_support_rick
 
Posts: 35092
Joined: Tue Mar 15, 2011 11:42 am

Re: My leds stay on?

Post by adafruit_support_rick »

MODE_HOLD is not the place for anything like this.

If you wanted to try to make something like this work, you would do it in case MODE_DATA, where the incoming data bytes are transferred to the WS2801:

Code: Select all

        if(bytesBuffered > 0) {
          SPDR = buffer[indexOut++];   // Issue next byte
          bytesBuffered--;
          bytesRemaining--;
          spiFlag = 1;
        }
You would need to declare another array to contain the previous data packet. There's a long comment block at line 42 that gives a description of the data packets that come from the host:

Code: Select all

// … The host software will need to
// generate a compatible header: immediately following the magic word
// are three bytes: a 16-bit count of the number of LEDs (high byte
// first) followed by a simple checksum value (high byte XOR low byte
// XOR 0x55).  LED data follows, 3 bytes per LED, in order R, G, B,
// where 0 = off and 255 = max brightness.
The header is checked in case MODE_HEADER. The LED data is processed in case MODE_DATA.

So, you would declare an array large enough to hold a complete packet's worth of LED data.
You need a boolean value - call it "noChange" - initialized to true.
You also need a counter. If "noChange" is still true after you make it through an entire packet, then you increment the counter. If "noChange" is false, then you reset the counter to 0.

Before copying a byte out to SPDR, you would first compare it against the corresponding byte in your "previous" data packet. If the two bytes are equal, you do not change the value of "noChange". If the two bytes are different, you set "noChange" to false. An easy way to do this is:
noChange = noChange & (<old byte> == <new byte>);

If noChange is false, you copy the new byte into the "previous" data packet buffer. (or don't waste time checking noChange - just copy it anyway).

Down in the ELSE clause (comment "// End of data -- issue latch:") is where you check the value of noChange and increment or reset your counter.
Pick a value where you want to turn the lights off. When the counter gets up to that value, you decide that the picture is paused, and set a "lightsOut" flag.
To avoid overflow problems, you probably should stop incrementing the counter once it gets to this point.

Now, you want to turn the lights off. Probably the simplest way to do this is to put a test into the same loop where you compare the data bytes. If your "lightsOut" flag is set, then instead of copying a data byte to SPDR, write a zero to it instead. You still want to keep doing all the "noChange" comparisons, so that you know when the picture starts changing again. When "noChange" starts ending up false, you will reset your counter and clear your "lightsOut" flag, and the lights will start operating normally again.

You're going to have to be careful to always increment indexOut properly, and in the right places too.

Good luck!

User avatar
schumi2004
 
Posts: 5
Joined: Mon Jan 02, 2012 5:04 am

Re: My leds stay on?

Post by schumi2004 »

Sorry for the late reply but forgot to thank you for the detailed explanation.
Since my programming skills aren't that good i think i should start reading some documentation on how to accomplish this.
Thanks again.

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

Return to “Arduino”