Notifications
Clear all

Theatre chase in opposite directions.

Page 11 / 11

Davy PS
(@davy-ps)
Trusted Member
Joined: 4 weeks ago
Posts: 73
Topic starter  

@robotbuilder 

Thanks Mate. Programme runs perfectly. Will spend next few days digesting learnings. 

 

Cheers,

 

Davy.


ReplyQuote
Lee G
(@lee-g)
Eminent Member
Joined: 1 year ago
Posts: 21
 

@robotBuilder, @Will, @DavyPS

Thanks, gentlemen. I have been following along with this topic from the beginning. I even purchased a reel of neopixels to play with. Thanks very much to @robotBuilder and @Will for their help and instructions in how to efficiently program this project. Very interesting… “wasted” many afternoons working on this. But, at 76, my days are not exactly filled with pressing matters.  Now trying to port it to RPi using Python. Will be trying to use two strips running independently lighting up the lights. (Hopefully… I don’t have it working yet).

Good Wishes to you and yours,

Lee


Jonnyr liked
ReplyQuote
Davy PS
(@davy-ps)
Trusted Member
Joined: 4 weeks ago
Posts: 73
Topic starter  

@robotbuilder 

Hi Mate. Been going over your last code. Printed it off and noted changes to effects as I change values. 

I have one area where I am confused. (One that I'm aware of anyway) ;-). 

How is this function actually applied in the context of this code. IE What does it do?

// == this is a function to swap values between two integer variables =====
void swapInt(int &a, int &b) {
int c = a;
a = b;
b = c;
}

I have attached entire code for reference point.

 

Cheers,

Davy.

 

#include <Adafruit_NeoPixel.h> //Indicates library is available for access.
#include <FastLED.h>           //Indicates library is available for access.

#define LED_PIN 4     //Arduino Ouput pin
#define NUM_LEDS 10  // Number of LEDS avaialble

#define BLACK  0  // Activates BLACK IE Switches led off.
#define RED    1  // Activates RED
#define GREEN  2  // Activates GREEN
#define BLUE   3  // Activates BLUE
#define YELLOW 4  // Activates YELLOW
#define PURPLE 5  // Activates PURPLE
#define GRAY   6  // Activates GRAY

CRGB leds[NUM_LEDS]; // []Indicates an array. In this case 10 LEDS.
// NUM_LEDS could also be expressed as [10];.

CRGB colorList[7] = {
                     {CRGB(0,0,0)},     // NO COLOR
                     {CRGB(0,255,0)},   // RED
                     {CRGB(255,0,0)},   // GREEN
                     {CRGB(0,0,255)},   // BLUE
                     {CRGB(255,255,0)}, // YELLOW
                     {CRGB(102,0,51)},  // PURPLE
                     {CRGB(51,51,0)},   // GRAY
                    };
//CRGB colorList[7] =. Array assigning colours to colour list.
//Each entry requires opening and closing curly brackets,
//with RGB values in parenthesis. Comma to complete after closing curly bracket.
//Comma acts as seperator.
//Curly brackets indicate start and end of function or statement. 
//Must be used as a pair IE Opening and Closing {}.Highlighting
//one bracket in code will identify opposite bracket.
// Check that values in parenthesis align with colour nominated.

                  
// == this is a function to swap values between two integer variables  =====
void swapInt(int &a, int &b) {
  int c = a;
  a = b;
  b = c;
}


void setup() {
  Serial.begin(9600); // 
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(100);
  // turn off all leds
  for (int ledNumber = 0; ledNumber < NUM_LEDS; ledNumber++) {
      leds[ledNumber] = colorList[BLACK];
  }
  FastLED.show();  // copy leds[] values to actual leds
}

int ledNumber2;   // working variable

int color1, color2;    // stores two colors
int loopCounter = 0;   // counts times loop() is repeated

void loop() {

  // decide what pair of colors to use for this loop() count
  if (loopCounter == 0){
    color1 = BLUE;
    color2 = RED;
  }

  if (loopCounter == 1){
    color1 = GREEN;
   color2 = YELLOW;
  }

  if (loopCounter == 2){
   color1 = PURPLE;
    color2 = GRAY;
  }

  // update loopCounter
  loopCounter = loopCounter + 1;
  if (loopCounter == 3){
    loopCounter = 0;        // reset counter
  }

  for (int ledNumber1 = 0; ledNumber1 < NUM_LEDS; ledNumber1++)  // for each led
  { 

    // swap colors half way to give bounce off each other effect
    if (ledNumber1 == 5){
      swapInt(color1,color2);
    }
    
    leds[ledNumber1] = colorList[color1];
    ledNumber2 = 9 - ledNumber1;
    leds[ledNumber2] = colorList[color2];
    FastLED.show();
    delay(100);
    leds[ledNumber1] = colorList[BLACK]; //turn off led
    leds[ledNumber2] = colorList[BLACK]; //turn off led
    FastLED.show();
    delay(0); //Time turned off.
  }

}

 


ReplyQuote
Davy PS
(@davy-ps)
Trusted Member
Joined: 4 weeks ago
Posts: 73
Topic starter  

@lee-g 

Hi Lee. I started my electronics career around  three months ago. Trying like mad to get me head around programming. robotBuilder and Will have been a great support and freely giving of their time and knowledge. Once I get to a level where I feel comfortable I am going to try and set up an ATMEGA chip to run independently of USB on breadboard powered by 2X9V batteries in parallel down through a 7805 IC to give me 5V. 

 

Cheers,

Davy.


ReplyQuote
robotBuilder
(@robotbuilder)
Noble Member
Joined: 3 years ago
Posts: 1100
 

@davy-ps 

How is this function actually applied in the context of this code. IE What does it do?

// == this is a function to swap values between two integer variables =====
void swapInt(int &a, int &b) {
int c = a;
a = b;
b = c;
}

 

It swaps the values of color1 and color2.

// values before executing swapInt()

color1 == BLUE
color2 == YELLOW

swapInt(color1,color2)

// values after executing swapInt()

color1 == YELLOW
color2 == BLUE

This post was modified 1 week ago by robotBuilder

ReplyQuote
Page 11 / 11