This has had me stumped for a few days now! I've a lot of programming experience but new to C++ and Arduino..
I've an array (_RGBpins) whose values randomly/unexpectedly change over time.
Below is a cut down sketch which replicated the problem with serial debugging.
#include "rgbled.h"
RGBLed rgbled(6,7,8);
//The setup function is called once at startup of the sketch
void setup()
{
Serial.begin(9600);
Serial.print("started ");
}
// The loop function is called in an endless loop
void loop()
{
byte white[] = {255,255,255};
byte black[] = {0,0,0};
rgbled.tempChange(white);
delay(3000);
rgbled.tempChange(black);
}
rgbled.cpp
#include "rgbled.h"
#include "Arduino.h"
// led pins
byte _RGBpins[3];
// constructor function
RGBLed::RGBLed(byte redPin, byte greenPin, byte bluePin) {
_RGBpins[0] = redPin;
_RGBpins[1] = greenPin;
_RGBpins[2] = bluePin;
for (byte i = 0; i < 3; i++) {
pinMode(_RGBpins[i], OUTPUT);
}
}
void RGBLed::tempChange(byte rgb[]) {
Serial.print(" pins:");
for (byte i = 0; i < 3; i++) {
Serial.print(_RGBpins[i]); // values in _RGBpins change randomly!?!
Serial.print(",");
}
}
rgbled.h
#ifndef RGBLED_H_
#define RGBLED_H_
#include "Arduino.h"
class RGBLed {
public:
RGBLed(byte redPin, byte greenPin, byte bluePin);
void tempChange(byte rgb[]);
private:
byte _RGBpins[];
};
#endif
thanks in advance..