Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Array value change unexpectedly over time on: November 11, 2012, 01:19:52 am
Thanks heaps Nick!

Haven't had much experience with header files before, didn't realise the size needed to be set there too.

Also I'd noticed some constructor problems earlier, will go with your begin() suggestions thanks!

 smiley
2  Using Arduino / Programming Questions / Array value change unexpectedly over time on: November 10, 2012, 11:35:21 pm
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.

Code:
#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
Code:
#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
Code:
#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..
3  Using Arduino / Programming Questions / Re: Time and TimeAlarms Libraries – Ask here for help or suggestions on: November 07, 2012, 08:00:54 pm
I believe the following page would benefit from some additional info - http://www.arduino.cc/playground/Code/time

i.e. now( ) returns the number of seconds elapsed since midnight 1/1/1970

As a newbie to Arduino, but with lots of programming experience elsewhere. I was looking for a function which did this but it took me a awhile before I realised what now() returned...  smiley-red
Pages: [1]