Page 1 of 1
Forum

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!



Coding help needed ...
 
Share:
Notifications
Clear all

[Solved] Coding help needed "Cylon" eye

7 Posts
2 Users
0 Likes
1,521 Views
(@jbunes72)
Active Member
Joined: 7 years ago
Posts: 4
Topic starter  

I have downloaded "USER: Hans" "Cylon" scanner and would like to make the following changes to his code.
Is there a way to control Color, Speed delay, eyesize, amount of trailing LEDs, and width of used LEDS (if my strip is 43 LEDs long and I want to shrink both sides by an equal amount, lets say up to 8)? within the code you have posted. All of these function to be changed with analog input from potentiometer.
I would like to use HSV as from what I have read that is a more visually pleasing color trasition. With that is there a way to control that with a pot also, only going through the color cycle once?

Code Below:
#include "FastLED.h"
#define NUM_LEDS 43
CRGB leds[NUM_LEDS];
#define PIN 10
void setup()
{
  FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
// REPLACE FROM HERE
void loop() {
  CylonBounce(0xff, 0, 0, 4, 100, 50);
}
void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay){
  for(int i = 0; i < NUM_LEDS-EyeSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
  for(int i = NUM_LEDS-EyeSize-2; i > 0; i--) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    }
    setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  
  delay(ReturnDelay);
}
// REPLACE TO HERE
void showStrip() {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.show();
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H
   // FastLED
   FastLED.show();
 #endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
 #ifdef ADAFRUIT_NEOPIXEL_H 
   // NeoPixel
   strip.setPixelColor(Pixel, strip.Color(red, green, blue));
 #endif
 #ifndef ADAFRUIT_NEOPIXEL_H 
   // FastLED
   leds[Pixel].r = red;
   leds[Pixel].g = green;
   leds[Pixel].b = blue;
 #endif
}
void setAll(byte red, byte green, byte blue) {
  for(int i = 0; i < NUM_LEDS; i++ ) {
    setPixel(i, red, green, blue); 
  }
  showStrip();
}

   
ReplyQuote
(@jbunes72)
Active Member
Joined: 7 years ago
Posts: 4
Topic starter  

Bump


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2697
 

My apologies for the late response ... (my daytime job keeps demanding so much of my time )

You're looking for quite a few changes ... and I'm not in the position to build a setup to test, but I'll try to see what I can do to help.

As for controlling with a potentiometer; what should this influence? Speed? Color? Eyesize?
For Color; what kind of change are you looking for? Change the entire color for the whole bounce loop? Or transition colors from color 1 to color 2, static or during the loop?

I think we need a slightly better definition of what you're looking for. (not intended as criticism, just me not quite getting the details  ). 


   
ReplyQuote
(@jbunes72)
Active Member
Joined: 7 years ago
Posts: 4
Topic starter  

I have employed the help of someone from Fiverr to try to get this sorted out of for me,  I do appreciate your response and the original code.

What I am trying to do is change the color, speed, eyesize, brightness & width of used leds (my strip has 43 LEDs and want to shrink the scanner down to 23 used LEDs) on the fly from 5 different potentiometers input into arduino uno. I know I can change all of these values within the code, except I havent figured out how to change the amount of trailing LEDs.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2697
 

That a great idea (Fiverr), I've used Fiverr in the past for other purposes, but it most certainly is a great way to get this done.

Adding trailing LEDs would indeed come with some extra code. I'd have to play a little bit with it though to get that correctly implemented. An initial thought would be something like this:

void loop() {
  CylonBounce(0xff, 0, 0, 4, 100, 50, 4);
}
void CylonBounce(byte red, byte green, byte blue, int EyeSize, int SpeedDelay, int ReturnDelay, int TrailSize){
  for(int i = 0; i < NUM_LEDS-EyeSize-TrailSize-2; i++) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    } for(int j = EyeSize; j <= EyeSize+TrailSize; j++) { setPixel(i+j, red/10, green/10, blue/10); }
    //setPixel(i+EyeSize+1, red/10, green/10, blue/10);
    showStrip();
    delay(SpeedDelay);
  }
  delay(ReturnDelay);
  for(int i = NUM_LEDS-EyeSize-TrailSize-2; i > 0; i–) {
    setAll(0,0,0);
    setPixel(i, red/10, green/10, blue/10);
    for(int j = 1; j <= EyeSize; j++) {
      setPixel(i+j, red, green, blue); 
    } for(int j = EyeSize; j<=EyeSize+TrailSize; j++) { setPixel(i+EyeSize+j, red/10, green/10, blue/10); }
    showStrip();
    delay(SpeedDelay);
  }
  
  delay(ReturnDelay);
}

I have not been able to test this, by lack of having an Arduino + LED strip available, so it might not work as expected.

Would you mind posting the result? (I'd understand if you'd rather not)


   
ReplyQuote
(@jbunes72)
Active Member
Joined: 7 years ago
Posts: 4
Topic starter  

I will post results when completed. I'll give your idea a shot in the mean time.


   
ReplyQuote
 Hans
(@hans)
Famed Member Admin
Joined: 11 years ago
Posts: 2697
 

Cool - thanks ! 


   
ReplyQuote
Share: