Page 1 of 1

Coding help needed "Cylon" eye

Coding help needed "Cylon" eye

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.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.




RSS Feed

Home Forums Hardware Arduino Coding help needed "Cylon" eye

This topic contains 6 replies, has 2 voices, and was last updated by  hans 2 months, 1 week ago.

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • 8233

    jbunes72
    Participant

    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();
    }
    • This topic was modified 2 months, 1 week ago by  jbunes72.
    • This topic was modified 2 months, 1 week ago by  jbunes72. Reason: Added code
    Attachments:
    You must be logged in to view attached files.
    8287

    jbunes72
    Participant

    Bump

    8295

    hans
    Keymaster

    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  ). 

    8300

    jbunes72
    Participant

    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.

    8302

    hans
    Keymaster

    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)

    8306

    jbunes72
    Participant

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

    8308

    hans
    Keymaster

    Cool – thanks ! 

Viewing 7 posts - 1 through 7 (of 7 total)



You must be logged in to reply to this topic.