Split/Dual "Cylon" Modification help plz..

Split/Dual “Cylon” Modification help plz…

—Back again to try something simple now that I have:

60/m ws2811’s 400Hz RGB strip
Uno R2
1A 5v PS or 2.2A LiPo 4.2v battery
also have the cap on PS line for LED’s. Resistor on Din., just in case.

I played around a bit with example code and now would like to do a mod to the Cylon code.

Instead of just one dot, I want two. Have both start at opposite ends of the 60 LED strip, go towards the middle, bounce back to the ends, then loop.

I would also like to add two pots.

  1. So far I have managed to add “Speed” as the value of a pot on A1, then divided it by 32 to limit the delay to a max value of 32. Works good enough, but wonder if it could be done any better.
  2. A pot to colorshift the dots. Either by morphing thru the spectrum or doing hard changes between colors as the dots pan across. Prefer to morph across the spectrum.
    At one end of the pot’s travel It’d be nice to do auto colorshifting as it pans across automatically (rainbow march like…) vs. a steady color.

Ultimately though, I would like to change the Pot controls to values on the PWM inputs from a hobby RC Rx.

+Tod Kurt said a few days ago,

 "Servo pulses typically range between 1000 microseconds and 2000 microseconds, with 1500 microseconds being considered middle/neutral."

So you can do something like:
void loop() {
unsigned long duration = pulseIn(receiverPin, HIGH);
if( duration > 1700 ) { // stick pushed up
leds[0] = CRGB::Green;
}
else if( duration < 1300 ) { // stick pushed down
leds[0] = CRGB::Red;
}
else { // stick in the middle
leds[0] = CRGB::Yellow;
}
FastLED.show();
}

That code isnt what I’d use, but does give me ideas on how to get the value from the pin and begin to alter things with it.
So I would just need to convert the PWM values to something useful to alter Speed and Color.
Speed should be easy enough by division since I’ve already figured that out using a pot.
But color is going to hang me up until I start to see how to alter color as the dots pan across.

I figured there must be a way to just grab the PWM values for two or three pins and use them to alter Speed, Color and perhaps even Pattern selections for other demo’s/modes.
But for now, Speed and Color is fine and I can probably figure out how to change the pattern with a 3rd pin.

I’m fresh with coding and cludging my way thru coding, but beginning to catch on.

seems the code below needs to be copied, then pasted in proper positions and flipped. Limiting each dot their half of the positions…
I get lost after that :frowning:
I can kinda see what needs to be done and I tried a few things last night, but I got unexpected results and now come here to see if some of you can shed some wisdom on how to do this, hopefully simple project.

Here’s the meat of the Cylon code with a few comments inserted in by me-

void loop() {
// First slide the led in one direction
for(int i = 0; i < NUM_LEDS; i++) {
// When it reaches the middle it needs to stop and bounce back to the beginning.
// Set the i’th led to red
leds[i] = CRGB::Red;
// Show the leds
FastLED.show();
// now that we’ve shown the leds, reset the i’th led to black
leds[i] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(Speed);
}
// Now go in the other direction.
// I want this to begin at the same time as the above loop.
for(int i = NUM_LEDS-1; i >= 0; i–) {
// When it reaches the middle it needs to stop and bounce back to the end.
// Set the i’th led to red
leds[i] = CRGB::Red;
// Show the leds
FastLED.show();
// now that we’ve shown the leds, reset the i’th led to black
leds[i] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(Speed);
}
}

Thanks so much in advance for any guidance! :smiley:

~Blaine

Hi Synthtech, Erin posted a similar request to your first request (going from both sides to the middle) - see if you can work out from the code I posted there, on how to do it. Essentially, with the normal cylon code, pretend that you actually have half then number of pixels, and then set leds[i] and add in leds[real number of leds minus 1 - i] to do the same.

Here you go…

void loop() {
// First slide the led in one direction
for(int i = 0; i < (NUM_LEDS / 2) - 1; i++) {
// Set the i’th led to red
leds[i] = CRGB::Red;
leds[NUM_LEDS - i -1] = CRGB::Red;
// Show the leds
FastLED.show();
// now that we’ve shown the leds, reset the i’th led to black
leds[i] = CRGB::Black;
leds[NUM_LEDS - i -1] = CRGB::Black;
// Wait a little bit before we loop around and do it again
delay(30);
}

// Now go in the other direction.  
for(int i = (NUM_LEDS / 2)<s>1; i >= 0; i-</s>) {
	// Set the i'th led to red 
	leds[i] = CRGB::Red;
	leds[NUM_LEDS - i -1] = CRGB::Red;
	// Show the leds
	FastLED.show();
	// now that we've shown the leds, reset the i'th led to black
	leds[i] = CRGB::Black;
	leds[NUM_LEDS - i -1] = CRGB::Black;
	// Wait a little bit before we loop around and do it again
	delay(30);
}

@Mark_Ortiz
Thank you Mark! I see how it works now.
it was using “i” on both sides in each loop that was getting me stuck…

This should definitively get me going in the right direction. I can test it later tonight, but I can see it will work already without testing…

Now I need to extract a variable PWM signal from a Pin of 1000 to 2000 duration, check often and grab the current value to create variable
Color1
with it, then place Color1 in where Red is so I can have it run a spectrum of colors that span across 30 LED’s on each side, in synch.

Thanks again so much for your help Mark!

~Blaine

No problem. I’m shameless, I know :slight_smile: but if you have an Android device - please review my Xmas wallpaper! (or +1) the store page if you don’t - Thanks!

You got it! Anytime :slight_smile: Thanks again!

Thank you so much!

seems there’s an error here…

for(int i = (NUM_LEDS / 2)1; i >= 0; i-)

the API stops there saying:
Cylon2311SpeedCntrl.ino: In function ‘void loop()’:
Cylon2311SpeedCntrl:40: error: expected ‘,’ or ‘;’ before numeric constant
Cylon2311SpeedCntrl:40: error: expected primary-expression before ‘)’ token

banging my head here trying to figure out what is wrong :frowning:

Does the normal Cylon code work for you? Did you just replace right part of the code? Will look later

for(int i = (NUM_LEDS / 2)1; i >= 0; i-)

Should be:

for(int i = (NUM_LEDS / 2) - 1; i >= 0; i-- )

Good spot, Daniel. That’s what I get for just typing code straight into these comments.

after many more attempts I finally figured out the error Daniel pointed out.

Thanks!