Pages: [1]   Go Down
Author Topic: ws2801 rgb strip control question  (Read 577 times)
0 Members and 1 Guest are viewing this topic.
brooklyn, ny
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hello,
i have a project that uses a bunch of ws2801 rgb led strips (http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/LED/FLB%205060RGB%201m%20%20FLEX%20STRIP.pdf ) controlled by an arduino and the FASTSPI_LED library. i have a second arduino running a loop that provides a oscillating number from 0 -150 that gets sent to the first arduino via txrx and the EASYTRANSFER library.
here is my main loop-
if button is pressed->make the first led light up with whatever value is coming in from second arduino->move the led down one position->repeat this process until the button is released (creates a chasing effect of leds moving down the strip)
if button is released->turn off first led->move led down one position->repeat until button is pressed again (turns off leds one by one)

this loop takes each new value coming in and moves it down the line of leds, making it appear to be pulsing but in reality its just a bunch of lights changing position down a line (like a stadium of people doing the wave, each person doing whatever the person before did)

what i would like to achieve is a loop that when the button is pressed, a group of leds turns on and moves down the strips, pulsating the live value changes from the second arduino. (like a small group of people moving around the stadium doing the wave based on what amount of wave they are told to do, which is constantly changing)

heres the code im currently working with
Code:
#include <FastSPI_LED.h>
#include <EasyTransfer.h>
#define NUM_LEDS 160

struct CRGB {
  unsigned char r;
  unsigned char g;
  unsigned char b;
};

struct CRGB *leds;

#define PIN 4
EasyTransfer ET;

struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int fade;

};

//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;
void setup() {Serial.begin(9600);
  ET.begin(details(mydata), &Serial);
  pinMode(5, INPUT);
  FastSPI_LED.setLeds(NUM_LEDS);
  FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);
  FastSPI_LED.setDataRate(3);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_LPD6803);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_HL1606);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_595);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);

  FastSPI_LED.setPin(PIN);

  FastSPI_LED.init();
  FastSPI_LED.start();

  leds = (struct CRGB*)FastSPI_LED.getRGBData();
  memset(leds, 0, NUM_LEDS * 3);
}

void loop() {
 ET.receiveData();
  int button = analogRead(5); //button wired with pull up resistor.

  //  If the button is down, insert an incoming value (mydata.fade) at the beginning of the strip
  if(button < 900) {
 
      leds[0].r = mydata.fade;
      leds[0].g = mydata.fade;
      leds[0].b = mydata.fade;

  }
  FastSPI_LED.show();
  delay(10);
  // Show the current pattern

 
  // Move all the lights down one step
  for(int i = NUM_LEDS-1; i > 0; i-- ) {
      leds[i].r = leds[i-1].r;
      leds[i].g = leds[i-1].g;
      leds[i].b = leds[i-1].b;

  }

if (button > 900){  //if button is released, turn the first led off
 
      leds[0].r = 0;
      leds[0].g = 0;
      leds[0].b = 0;
    }
 FastSPI_LED.show();
 delay(20);

}

any ideas or nudges in the right direction would be very helpful.
thanks, tom
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8706
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Currently you are using the output buffer to keep track of the state of all the LEDs.  I think you will want a separate list of which LEDs are 'on'.

Note: You can't use analogRead() on a digital pin so I assume the button is on A5.  You don't need to set analog input pins with pinMode().

Try something like this:
Code:
#include <FastSPI_LED.h>
#include <EasyTransfer.h>
#define NUM_LEDS 160

boolean LEDstates[NUM_LEDS];  // Keep track of which LEDs are ON (1/HIGH/true) and OFF (0/LOW/false)

struct CRGB {
  unsigned char r;
  unsigned char g;
  unsigned char b;
};

struct CRGB *leds;

#define PIN 4
EasyTransfer ET;

struct RECEIVE_DATA_STRUCTURE{
  //put your variable definitions here for the data you want to receive
  //THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
  int fade;

};

//give a name to the group of data
RECEIVE_DATA_STRUCTURE mydata;
void setup() {
  Serial.begin(9600);
  ET.begin(details(mydata), &Serial);

  FastSPI_LED.setLeds(NUM_LEDS);
  FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);
  FastSPI_LED.setDataRate(3);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_LPD6803);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_HL1606);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_595);
  //FastSPI_LED.setChipset(CFastSPI_LED::SPI_WS2801);

  FastSPI_LED.setPin(PIN);

  FastSPI_LED.init();
  FastSPI_LED.start();

  leds = (struct CRGB*)FastSPI_LED.getRGBData();
  memset(leds, 0, NUM_LEDS * 3);
}

void loop() {
  ET.receiveData();
  int button = analogRead(A5); //button wired with pull up resistor.

  // Move all the lights down one step
  for(int i = NUM_LEDS-1; i > 0; i-- )
    LEDstates[i] = LEDstates[i-1];

  //  Insert a new LED state at the front of the list based on the button state
  LEDstates[0] = button < 900;

  // Copy the current brightness to all of the ON LEDs and turn the OFF LEDs off.
  for(int i=0; i<NUM_LEDS; i++) {
    leds[i].r =   LEDstates[i] ? mydata.fade : 0; // if (LEDstates[i]) leds[i].r = mydata.fade; else  leds[i].r = 0;
    leds[i].g =   LEDstates[i] ? mydata.fade : 0; // if (LEDstates[i]) leds[i].r = mydata.fade; else  leds[i].r = 0;
    leds[i].b =   LEDstates[i] ? mydata.fade : 0; // if (LEDstates[i]) leds[i].r = mydata.fade; else  leds[i].r = 0;
  }

  FastSPI_LED.show();
  delay(30);
}
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

brooklyn, ny
Offline Offline
Jr. Member
**
Karma: 0
Posts: 50
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hey john, thanks for the quick help!
this new list makes the code do just what i asked. i just added a millis counter to slow down the movement of the leds down the strip.
i have a new question, when the button is pressed, it lights up an led and copies the incoming value to all that light up. how can i make it so that it copies different values to different leds?
for example, instead of one group of leds fading in and out with my incoming values, i want this group to have fading waves or ripples based on the incoming values. would i have to make some for loop that changes the copied value?

another question i had was about my button. in my project the amount of time the button is held down determines how long the lit section of leds is. i want to be able to keep the button held down without actually holding it down. ie. pushing the button once makes the analog input stay low for a variable amount of time to determine the length of the lit section. how do i do this without adding a delay to the loop?

any help would be appreciated
Logged

Pages: [1]   Go Up
Jump to: