Go Down

Topic: Program two pins to do the same thing.... (Read 2134 times) previous topic - next topic

kamaroman68

sorry....



sketch_feb29a:39: error: 'pixels' was not declared in this scope

PaulS

Code: [Select]
    leftEye.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
    rightEye.setPixelColor(i, pixels.Color(0,150,0));

Apparently should be
Code: [Select]
    leftEye.setPixelColor(i, leftEye.Color(0,150,0)); // Moderately bright green color.
    rightEye.setPixelColor(i, rightEye.Color(0,150,0));

septillion

Ah, missed that part. But Color() is a static method so it doesn't matter from with object you call it

Code: [Select]

    leftEye.setPixelColor(i, rightEye.Color(0,150,0)); // Moderately bright green color.
    rightEye.setPixelColor(i, leftEye.Color(0,150,0));

Will work the same. I wouldn't recommend doing so because it's confusing for us but it does the same.

You can also call it from the class itself
Code: [Select]

    leftEye.setPixelColor(i, Adafruit_NeoPixel::Color(0,150,0)); // Moderately bright green color.
    rightEye.setPixelColor(i, Adafruit_NeoPixel::Color(0,150,0));

Maybe to most transparent approach because now you see the Color() method doesn't change anything in leftEye or rightEye.
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Whandall

I do not understand why the eyes should be driver by different pins at all.

How about daisy-chaining them and controlling the content of the transferred data?
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

septillion

That's very possible as well. But if  you have a pin and memory to spare I can see the added value of separate variables for the left and right eye just to make it clear and easy for a starter. But yeay, you can make one big string of 48 Neopixels.

Then I would do it like this:
Code: [Select]


// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif

const byte LeftEyePin = 6;
//const byte RightEyePin = 8;



// How many NeoPixels are attached to the Arduino?
const byte PixelsPerEye = 24;
const byte NumPixels = PixelsPerEye * 2; //const is preffered over define


// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
Adafruit_NeoPixel eyes = Adafruit_NeoPixel(NumPixels, LeftEyePin, NEO_GRB + NEO_KHZ800); //left eye neopixels

int delayval = 500; // delay for half a second

void setup() {
  eyes.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

  for(int i=0; i < PixelsPerEye; i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    eyes.setPixelColor(leftEye(i), Adafruit_NeoPixel::Color(0,150,0)); // Moderately bright green color.
    eyes.setPixelColor(rightEye(i), Adafruit_NeoPixel::Color(0,150,0)); // Moderately bright green color.   

    eyes.show(); // This sends the updated pixel color to the hardware.

    delay(delayval); // Delay for a period of time (in milliseconds).

  }
}

inline int leftEye(int val){
  return val;
}

inline int rightEye(int val){
  return val + PixelsPerEye;
}

This assumes the right eye is chained after the left
Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Whandall

The passed array could be defined two-dimensional, that would give a beginner an easy way to select the eye by index.
 I would pass pointers for the manipulating functions anyway.
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

septillion

Use fricking code tags!!!!
I want x => I would like x, I need help => I would like help, Need fast => Go and pay someone to do the job...

NEW Library to make fading leds a piece of cake
https://github.com/septillion-git/FadeLed

Whandall

The array that contains the RGB data? Probably allocated by
Code: [Select]
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
There is none? While usinge NeoPixels?
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

Whandall

I use FastLED and in that library you get a pointer to the data by calling a member function
Code: [Select]
    // returns pointer to the CRGB buffer for the first strip
CRGB *leds() { return (*this)[0].leds(); }
Ah, this is obviously some strange usage of the word 'safe' that I wasn't previously aware of. (D.Adams)

kamaroman68

Guys thank you very much. I come from the Plc world so this is very different to me. I seem to be having an issue understanding what the error messages actually mean. Believe me I tried changing the line that turned pink ( error on that line??) many times before reposting. Thanks again will try again when home.

Go Up