Show Posts
Pages: 1 [2] 3 4 5
16  Using Arduino / Sensors / Re: IR Remote Controller Library - Interrupt based rather than polled on: September 19, 2012, 04:43:37 pm
Doesn't seem to work for me neither.

The Ken Shirriff's library (http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html) can decode my apple remote (NEC protocol) perfect. But here I'll get different values all the time (like capsid in the previous post).

I would like to try this one since it supports interrupts, but something seems to be broken.
17  Using Arduino / Programming Questions / Re: Arduino 1.0 new Serial commands on: August 18, 2012, 03:46:27 am
You can do this much simpler now with the parseInt and parseFloat commands.
If you use newline as terminator (/n) you can just type the command in your serial monitor and press enter.

The example online.
http://arduino.cc/en/Tutorial/ReadASCIIString

Just put commas, spaces or other characters in between the numbers, it works all.
18  Using Arduino / Programming Questions / Tips for further optimizing this Perlin noise function on: August 16, 2012, 03:51:32 am
I'm trying to create a more optimized function of the perlin noise algorithm to use in a light installation.
I would like to know if someone sees more possibilities to improve the speed.

Its now pretty fast already (compared with versions I've tried already) and I'm happy with how it looks (sure the other ones are more sophisticated)  

It takes about 7 milliseconds for 20 lights. However its just one octave of noise. Two octaves take already 12 milliseconds.
With other interpolations (not lerp but cosine) calculation time will grow fast.

Just to give you an insight of my progress:

I've tested different implementations of the algorithm already. They all took longer than about 20 milliseconds.
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191768812 (Two implementations).
http://happyinmotion.livejournal.com/278357.html (Simplex noise)

And I've read some explanations about the algorithm:
http://freespace.virgin.net/hugo.elias/models/m_perlin.html
http://www.gamedev.net/blog/73/entry-1382657-fast-perlin-noise/

I've finally ended up with the version below mainly based on this source (which is kind of the same as the Mike Edwards implementations from the forum post). For me it was easy to undress this code, because it uses clear functions and naming:
http://code.google.com/p/britable/source/browse/trunk/britable/britable.pde

I partly understand the Maths behind it the algorithm, that makes it difficult to come up with good solutions myself (I tried but failed..).

One improvement I can think of can be the use of a lookup table with  random values instead of the randomGenerator used. The lookup table can't be massive either due memory constraints.

But is it worth it and how do I implement it in the functions below?  

There are examples that use a lookup table (like the 2nd example in this topic: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1191768812), but this code is kind of messy (or at least not clear from a programming perspective, I think a mathematician wouldn't have trouble reading this).

Below a script where I measure the timing and that prints out some values to check if it works in the Serial monitor.

I suppose its already useful for people who want to do something with this and some leds, so feel free to use it.

I've added the code in an .ino file as attachment as well.

Code:
/* Code based on perlin function in this source
   http://code.google.com/p/britable/source/browse/trunk/britable/britable.pde#
   http://code.google.com/p/britable/

   kasperkamperman.com 16-09-2012
*/

const byte amountOfLights = 20;

byte lightArray[amountOfLights];  // lightArray is in bytes just values in range of 0 - 255

unsigned long currentTime;     // for time measuring purposes
unsigned long passedTime;     // for time measuring purposes
unsigned long longestTime = 0; // for time measuring purposes

float perlinTimeInc      = 0.07;
float perlinXInc         = 0.05;  
float perlinTimePosition;

void setup()
{   Serial.begin(57600);
}

void loop()
{  
    currentTime = micros(); // store current time
    
    for(byte i=0;i<amountOfLights;i++)
    {
      float x = float(i)*perlinXInc; // input for x value in the renderNoise function
      
      byte val = renderNoise(x, perlinTimePosition);
      lightArray[i] = val;
    }
    
    // go a step further in time (input for y function in perlin noise)
    perlinTimePosition = perlinTimePosition + perlinTimeInc;  
    
    // calculate the time the whole calculation took
    passedTime = micros()-currentTime;
    
    // because times will variate, remember the maximum time it took
    if(passedTime>longestTime) longestTime = passedTime;
    
    // print the time it took for the current calculation and the maximum time
    Serial.print("time:  ");
    Serial.print(passedTime);
    Serial.print(" max: ");
    Serial.println(longestTime);
    Serial.print("array: ");
    
    // print the array to see the result
    // I calculate back to float just for printing purposes
    // I this way so actually see a perlin effect
    for(byte i=0;i<amountOfLights;i++)
    { float printFloat = (lightArray[i]/255.0) * 9;
      Serial.print(printFloat,0);
      Serial.print(", ");
    }
    Serial.println();
    Serial.println();
    
    delay(50);
}

// returns a value between 0 - 255 for lights
byte renderNoise(float x, float y)
{
  float noise;
  
  // 2 octaves
  //noise = perlin_function(x,y) + perlin_function(x*2,y*2);
  
  noise = perlin_function(x,y); // gives noise in the range of -1 to +1
  noise = noise *128+127;       // scale to a number between 0 - 255
  
  return (byte) noise;  
}

float perlin_function(float x, float y)
{
  int fx = floor(x);
  int fy = floor(y);
  
  float s,t,u,v;
  s=perlin_noise_2d(fx,fy);
  t=perlin_noise_2d(fx+1,fy);
  u=perlin_noise_2d(fx,fy+1);
  v=perlin_noise_2d(fx+1,fy+1);
  
  float inter1 = lerp(s,t,x-fx);
  float inter2 = lerp(u,v,x-fx);  

  return lerp(inter1,inter2,y-fy);
}

float perlin_noise_2d(int x, int y) {
  long n=(long)x+(long)y*57;
  n = (n<<13)^ n;
  return 1.0 - (((n *(n * n * 15731L + 789221L) + 1376312589L)  & 0x7fffffff) / 1073741824.0);    
}

float lerp(float a, float b, float x)
{ return a + x * (b - a);
}









19  Using Arduino / Interfacing w/ Software on the Computer / Re: Can Arduino send OSC information? on: May 04, 2012, 11:09:46 am
Yes of course. I had good experience with this library: https://github.com/djiamnot/Z_OSC
20  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino Mega 2560 + Firmata + AS3Glue on: October 20, 2011, 06:16:07 am
Changes are now also included on the As3glue google code site and a program example in the as3glue bundle:

http://code.google.com/p/as3glue/downloads/detail?name=arduino_as3glue_bundle_v20.zip
21  Using Arduino / Interfacing w/ Software on the Computer / Re: interfacing arduino mega 2560 with Flash [firmata+AS3Glue 1.6] on: October 20, 2011, 06:12:09 am
I've included the changes from Mochammad on the as3glue site and in the bundle (including a modified example):
http://code.google.com/p/as3glue/downloads/detail?name=arduino_as3glue_bundle_v20.zip
22  Using Arduino / Programming Questions / Re: library hierarchy, inheritance on: October 03, 2011, 12:08:08 pm
Thank you, that did it.
23  Using Arduino / Programming Questions / Re: library hierarchy, inheritance on: October 03, 2011, 09:33:08 am
I've found this introduction: http://www.cs.bu.edu/teaching/cpp/inheritance/intro/

Here I've found that I can say which method from which class I'd like to use:

I've modfied this in the .cpp file.
Code:
#include "WProgram.h"
#include "ColorLight_effect.h"

Effect::Effect() : ColourPalette()
{ /*
for (int i=0;i<23; i++)
{ noiseArray[i] = 0;
colorArray[i] = 0;
};

for (int i=0;i<256; i++)
{ colorMap[i] = 0;
};
*/
Serial.println("constructor effect");
}

unsigned long lerpColorRGB(unsigned long c1, unsigned long c2, float amt)
{
  unsigned long a1 = (c1 >> 24) & 0xFF;
  unsigned long r1 = (c1 >> 16) & 0xff;
  unsigned long g1 = (c1 >> 8)  & 0xff;
  unsigned long b1 = c1 & 0xff;
 
  unsigned long a2 = (c2 >> 24) & 0xFF;
  unsigned long r2 = (c2 >> 16) & 0xff;
  unsigned long g2 = (c2 >> 8)  & 0xff;
  unsigned long b2 = c2 & 0xff;
 
  unsigned long ao = ColourPalette::lerpf(a1, a2, amt);
  unsigned long ro = ColourPalette::lerpf(r1, r2, amt);
  unsigned long go = ColourPalette::lerpf(g1, g2, amt);
  unsigned long bo = ColourPalette::lerpf(b1, b2, amt);
 
  return ColourPalette::colorInt(ao,ro,go,bo);
}

I get now I slightly different error:
Code:
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp: In function 'long unsigned int lerpColorRGB(long unsigned int, long unsigned int, float)':
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp:30: error: cannot call member function 'int ColourPalette::lerpf(int, int, float)' without object
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp:31: error: cannot call member function 'int ColourPalette::lerpf(int, int, float)' without object
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp:32: error: cannot call member function 'int ColourPalette::lerpf(int, int, float)' without object
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp:33: error: cannot call member function 'int ColourPalette::lerpf(int, int, float)' without object
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp:35: error: cannot call member function 'long unsigned int ColourPalette::colorInt(long unsigned int, long unsigned int, long unsigned int, long unsigned int)' without object
24  Using Arduino / Programming Questions / Re: library hierarchy, inheritance on: October 03, 2011, 09:19:14 am
I just tried to add this
Code:
Effect::Effect() : ColourPalette()
but it doesn't seem to make any difference I still get the errors. I noticed to when I remove this :ColourPalette() that the constructor of the colourpalette constructor is called the same.

Code:
started
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourpalette
constructor effect

Can it be something else as well?
25  Using Arduino / Programming Questions / library hierarchy, inheritance on: October 03, 2011, 08:35:40 am
Hi,

I'd like to write a class that inherits from another class I've written. This works partly. Problem is that I cannot use functions in a function of the inherited class. I get this error:
Code:
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp:27: error: 'lerpf' was not declared in this scope
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight_effect.cpp:32: error: 'colorInt' was not declared in this scope

I couldn't find any information on this. There is a tutorial, but thats partly finished:
http://www.arduino.cc/playground/Code/Hierarchy

This is the .h file of the "main" class
Code:
#ifndef ColorLight_h
#define ColorLight_h

#include "WProgram.h"

class ColourBase
{
  public:
    ColourBase(); 
   
    float interpolation;
   
  int baseHue;           
unsigned long wheelColor[4];
unsigned long tintColor[4];
unsigned long shadeColor[4];
unsigned long interpolatedColor[4];
};

class ColourPalette
{
  public:
    ColourPalette();
   
    void setHue(int);
void setComplementOffset(int);
void setHueAngle(int);

unsigned long getColour(byte);

unsigned long colorInt(unsigned long, unsigned long, unsigned long, unsigned long);
unsigned long colorInt(unsigned long, unsigned long, unsigned long);

  int mainHue;
int complementOffset;
int hueAngle;
int complementAngle;

int minSaturation;
int maxSaturation;
int minBrightness;
int maxBrightness;

ColourBase cArray[6];

void updatePalette();

void calculateShadeTint(ColourBase&);
void updateInterpolation(ColourBase&);
void calculateRGB(ColourBase &);

void getRGB(unsigned long*);

int   lerpf(int, int, float);
};

#endif

And the .h of the effect class that inherits from the ColourPalette.
Code:
#include "WProgram.h"

#ifndef ColorLight_effect_h
#define ColorLight_effect_h

#include "ColorLight.h"

class Effect : public ColourPalette
{ public:
Effect();

float time; // time
  float contrast;
 
  byte   noiseArray[23];
  int    colorArray[23];
  unsigned long colorMap[256];
 
  unsigned long lerpColorRGB(unsigned long, unsigned long, float);
};

#endif

In the lerpColorRGB function I'd like to use two functions of the ColourPalette class.
lerpf and colorInt

The .cpp file.
Code:
#include "WProgram.h"
#include "ColorLight_effect.h"

Effect::Effect()
{ for (int i=0;i<23; i++)
{ noiseArray[i] = 0;
colorArray[i] = 0;
};

for (int i=0;i<256; i++)
{ colorMap[i] = 0;
};
}

unsigned long lerpColorRGB(unsigned long c1, unsigned long c2, float amt)
{
  unsigned long a1 = (c1 >> 24) & 0xFF;
  unsigned long r1 = (c1 >> 16) & 0xff;
  unsigned long g1 = (c1 >> 8)  & 0xff;
  unsigned long b1 = c1 & 0xff;
 
  unsigned long a2 = (c2 >> 24) & 0xFF;
  unsigned long r2 = (c2 >> 16) & 0xff;
  unsigned long g2 = (c2 >> 8)  & 0xff;
  unsigned long b2 = c2 & 0xff;
 
  unsigned long ao = lerpf(a1, a2, amt);
  unsigned long ro = lerpf(r1, r2, amt);
  unsigned long go = lerpf(g1, g2, amt);
  unsigned long bo = lerpf(b1, b2, amt);
 
  return colorInt(ao,ro,go,bo);
}
26  Using Arduino / Programming Questions / Re: a pointer to a multidimensional array on: September 21, 2011, 02:27:36 pm
I don't get the strange readings when I init like this:

Code:
ColourBase::ColourBase()
{ interpolation = 0.5;
baseHue = 0;

for (int i=0;i<3; i++)
{
wheelHSBColor[i]        = 1;
tintHSBColor[i]         = 1;
shadeHSBColor[i]        = 1;
interpolatedHSBColor[i] = 1; // interpolated color between shade/tint
}

wheelRGBColor = 0;   
    shadeRGBColor = 0;
    tintRGBColor  = 0;   
    interpolatedRGBColor = 0;

Serial.println("constructor colourbase");
}

I've found out that the values are not set then in the updateInterpolation function:
Code:
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
- function update palette

- function ColourAtRYBWheel result: 4,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 4 c.shadeHSBColor[0]: 4
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
- function updateInterpolation
  c.tintHSBColor[0]: 1 c.shadeHSBColor[0]: 1
  c.tintHSBColor[1]: 1 c.shadeHSBColor[1]: 1
  c.tintHSBColor[2]: 1 c.shadeHSBColor[2]: 1

- function ColourAtRYBWheel result: 321,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 321 c.shadeHSBColor[0]: 321
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
- function updateInterpolation
  c.tintHSBColor[0]: 1 c.shadeHSBColor[0]: 1
  c.tintHSBColor[1]: 1 c.shadeHSBColor[1]: 1
  c.tintHSBColor[2]: 1 c.shadeHSBColor[2]: 1

- function ColourAtRYBWheel result: 26,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 26 c.shadeHSBColor[0]: 26
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
- function updateInterpolation
  c.tintHSBColor[0]: 1 c.shadeHSBColor[0]: 1
  c.tintHSBColor[1]: 1 c.shadeHSBColor[1]: 1
  c.tintHSBColor[2]: 1 c.shadeHSBColor[2]: 1

- function ColourAtRYBWheel result: 131,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 131 c.shadeHSBColor[0]: 131
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
- function updateInterpolation
  c.tintHSBColor[0]: 1 c.shadeHSBColor[0]: 1
  c.tintHSBColor[1]: 1 c.shadeHSBColor[1]: 1
  c.tintHSBColor[2]: 1 c.shadeHSBColor[2]: 1

- function ColourAtRYBWheel result: 92,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 92 c.shadeHSBColor[0]: 92
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
- function updateInterpolation
  c.tintHSBColor[0]: 1 c.shadeHSBColor[0]: 1
  c.tintHSBColor[1]: 1 c.shadeHSBColor[1]: 1
  c.tintHSBColor[2]: 1 c.shadeHSBColor[2]: 1

- function ColourAtRYBWheel result: 188,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 188 c.shadeHSBColor[0]: 188
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
- function updateInterpolation
  c.tintHSBColor[0]: 1 c.shadeHSBColor[0]: 1
  c.tintHSBColor[1]: 1 c.shadeHSBColor[1]: 1
  c.tintHSBColor[2]: 1 c.shadeHSBColor[2]: 1

However I tried to call the updateInterpolation function from the calculateShadeTint function like this.
Code:
updateInterpolation(c); 
and removed it from this for-loop
Code:
for (int i=0; i<6;i++)
{ // convert to new hue numbers with the new ColorWheel (HueToRYB)
    ColourAtRYBWheel(cArray[i].baseHue, cArray[i].wheelHSBColor);
    calculateShadeTint(cArray[i]); 
    //updateInterpolation(cArray[i]); 
}

And now I get the right values.
Code:
- function ColourAtRYBWheel result: 4,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 4 c.shadeHSBColor[0]: 4
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
- function updateInterpolation
  c.tintHSBColor[0]: 4 c.shadeHSBColor[0]: 4
  c.tintHSBColor[1]: 128 c.shadeHSBColor[1]: 128
  c.tintHSBColor[2]: 128 c.shadeHSBColor[2]: 128
.... etc

But its seems strange to me that it doesn't work in the other way, since Arduino has no threading I think and walks through the code in a lineair way?
27  Using Arduino / Programming Questions / Re: a pointer to a multidimensional array on: September 21, 2011, 12:15:50 pm
Sorry, I needed to make a smaller version of my project to show the problem in the forum, because otherwise the code gets to lengthy.
Below I did.

My .h file:
Code:
#include "WProgram.h"

#ifndef ColorLight_h
#define ColorLight_h

class ColourBase
{
  public:
    ColourBase(); 
   
    float interpolation;
   
  int baseHue;           // hue value on the circle 
int wheelHSBColor[3];
int tintHSBColor[3];
int shadeHSBColor[3];
int interpolatedHSBColor[3]; // interpolated color between shade/tint

unsigned long wheelRGBColor;   
    unsigned long shadeRGBColor;
    unsigned long tintRGBColor;   
    unsigned long interpolatedRGBColor;
};

class ColourPalette
{
  public:
    ColourPalette();
   
protected:
 
int mainHue;
int complementOffset;
int hueAngle;
int complementAngle;

int minSaturation;
int maxSaturation;
int minBrightness;
int maxBrightness;

ColourBase cArray[6];

void setMinSaturation(int);
void setMaxSaturation(int);
void setMinBrightness(int);
void setMaxBrightness(int);

void updatePalette();

void setShadeValues(float, float, float , float);
void calculateShadeTint(ColourBase);

void updateInterpolation(ColourBase);

void ColourAtRYBWheel(int, int*);

int   lerpInt(int, int, int, int);
int   lerpf(int, int, float);

};

#endif

My .cpp file
Code:
#include "WProgram.h"
#include "ColorLight.h"

const int rybHueWheel[25] =
{ 0  , 12 , 24 , 30 , 36 , 42 , 48 , 54 , 60 , 72 , 84 , 108, 120, 154, 180, 206, 225, 240, 260, 265, 280, 300, 315, 333, 360 };

ColourBase::ColourBase()
{ interpolation = 0.5;
baseHue = 0;
Serial.println("constructor colourbase");
}

ColourPalette::ColourPalette()
{
//for (int i=0;i<6; i++)
    //{ //cArray[i] = ColourBase();
    //}

// defaults
mainHue = 5;
complementOffset = 0;
hueAngle = 30;
complementAngle = 30;   

minSaturation = 0;
maxSaturation = 255;
minBrightness = 0;
maxBrightness = 255;

updatePalette();
}

// =FUNCTIONS====================================================

void ColourPalette::updatePalette()
{
  Serial.println("- function update palette");
  cArray[0].baseHue = mainHue;
  cArray[1].baseHue = mainHue - hueAngle;
  cArray[2].baseHue = mainHue + hueAngle;
  cArray[3].baseHue = mainHue + 180 + complementOffset;
  cArray[4].baseHue = cArray[3].baseHue - complementAngle;
  cArray[5].baseHue = cArray[3].baseHue + complementAngle;
 
  for (int i=0; i<6;i++)
  { // convert to new hue numbers with the new ColorWheel (HueToRYB)
  ColourAtRYBWheel(cArray[i].baseHue, cArray[i].wheelHSBColor);
    calculateShadeTint(cArray[i]); 
    updateInterpolation(cArray[i]); 
  } 
}

void ColourPalette::ColourAtRYBWheel(int hue, int c[3])
{
if (hue<0)    hue = 360+hue;     
hue = hue%360; // stick to 0 - 359

int rybWheelIndex  = hue/15;      // colourWheel has 24 base colours
int rybWheelAmount = hue%15;

c[0] = lerpInt(rybHueWheel[rybWheelIndex], rybHueWheel[rybWheelIndex+1], rybWheelAmount,15);
c[1] = 255; // saturation
c[2] = 255; // brightness

Serial.println();
Serial.print("- function ColourAtRYBWheel result: ");
Serial.print(c[0],DEC);
Serial.print(","); 
Serial.print(c[1],DEC); 
Serial.print(","); 
Serial.println(c[2],DEC); 
}

void ColourPalette::calculateShadeTint(ColourBase c)
{   Serial.println("- function calculateShadeTint");

c.tintHSBColor[0] = c.shadeHSBColor[0] = c.wheelHSBColor[0];
c.shadeHSBColor[1] = minSaturation;
c.tintHSBColor[1]  = maxSaturation; 
c.shadeHSBColor[2] = minBrightness;
c.tintHSBColor[2]  = maxBrightness; 

Serial.print("  c.tintHSBColor[0]: ");
Serial.print(c.tintHSBColor[0]);
Serial.print(" c.shadeHSBColor[0]: ");
Serial.println(c.shadeHSBColor[0]);

Serial.print("  c.tintHSBColor[1]: ");
Serial.print(c.tintHSBColor[1]);
Serial.print(" c.shadeHSBColor[1]: ");
Serial.println(c.shadeHSBColor[1]);
   
Serial.print("  c.tintHSBColor[2]: ");
Serial.print(c.tintHSBColor[2]);
Serial.print(" c.shadeHSBColor[2]: ");
Serial.println(c.shadeHSBColor[2]);   
}

void ColourPalette::updateInterpolation(ColourBase c)
{
Serial.println("- function updateInterpolation");

Serial.print("  c.tintHSBColor[0]: ");
Serial.print(c.tintHSBColor[0]);
Serial.print(" c.shadeHSBColor[0]: ");
Serial.println(c.shadeHSBColor[0]);

Serial.print("  c.tintHSBColor[1]: ");
Serial.print(c.tintHSBColor[1]);
Serial.print(" c.shadeHSBColor[1]: ");
Serial.println(c.shadeHSBColor[1]);

Serial.print("  c.tintHSBColor[2]: ");
Serial.print(c.tintHSBColor[2]);
Serial.print(" c.shadeHSBColor[2]: ");
Serial.println(c.shadeHSBColor[2]); 
}

int ColourPalette::lerpInt(int a, int b, int f, int max)
{ // f is a number between 0 - max
return a + ( (b-a) * f/max );
}

In the function calculateShadeTint I expect to read the same values as in updateInterpolation.
Below you'll see that that doesn't happen.

What is printed:
Code:
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
constructor colourbase
- function update palette

- function ColourAtRYBWheel result: 4,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 4 c.shadeHSBColor[0]: 4
  c.tintHSBColor[1]: 255 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 255 c.shadeHSBColor[2]: 0
- function updateInterpolation
  c.tintHSBColor[0]: -19659 c.shadeHSBColor[0]: -257
  c.tintHSBColor[1]: -4910 c.shadeHSBColor[1]: -1265
  c.tintHSBColor[2]: 16309 c.shadeHSBColor[2]: -722

- function ColourAtRYBWheel result: 321,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 321 c.shadeHSBColor[0]: 321
  c.tintHSBColor[1]: 255 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 255 c.shadeHSBColor[2]: 0
- function updateInterpolation
  c.tintHSBColor[0]: -19659 c.shadeHSBColor[0]: -257
  c.tintHSBColor[1]: -4910 c.shadeHSBColor[1]: -1265
  c.tintHSBColor[2]: 16309 c.shadeHSBColor[2]: -722

- function ColourAtRYBWheel result: 26,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 26 c.shadeHSBColor[0]: 26
  c.tintHSBColor[1]: 255 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 255 c.shadeHSBColor[2]: 0
- function updateInterpolation
  c.tintHSBColor[0]: 1536 c.shadeHSBColor[0]: 9734
  c.tintHSBColor[1]: 38 c.shadeHSBColor[1]: -18426
  c.tintHSBColor[2]: 0 c.shadeHSBColor[2]: 19974

- function ColourAtRYBWheel result: 131,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 131 c.shadeHSBColor[0]: 131
  c.tintHSBColor[1]: 255 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 255 c.shadeHSBColor[2]: 0
- function updateInterpolation
  c.tintHSBColor[0]: 1791 c.shadeHSBColor[0]: 1025
  c.tintHSBColor[1]: 1236 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 1061 c.shadeHSBColor[2]: -512

- function ColourAtRYBWheel result: 92,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 92 c.shadeHSBColor[0]: 92
  c.tintHSBColor[1]: 255 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 255 c.shadeHSBColor[2]: 0
- function updateInterpolation
  c.tintHSBColor[0]: 6913 c.shadeHSBColor[0]: 1280
  c.tintHSBColor[1]: 614 c.shadeHSBColor[1]: 19459
  c.tintHSBColor[2]: -6656 c.shadeHSBColor[2]: 11776

- function ColourAtRYBWheel result: 188,255,255
- function calculateShadeTint
  c.tintHSBColor[0]: 188 c.shadeHSBColor[0]: 188
  c.tintHSBColor[1]: 255 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 255 c.shadeHSBColor[2]: 0
- function updateInterpolation
  c.tintHSBColor[0]: 0 c.shadeHSBColor[0]: 0
  c.tintHSBColor[1]: 0 c.shadeHSBColor[1]: 0
  c.tintHSBColor[2]: 0 c.shadeHSBColor[2]: 0

28  Using Arduino / Programming Questions / Re: a pointer to a multidimensional array on: September 21, 2011, 11:08:59 am
And back again with another question. .. smiley-sad

I think I have a problem with the Colourbase objects. Because I get back some messed up values again. 

I initialize my ColourBase objects like this:
Code:
for (int i=0;i<6; i++)
{ cArray[i] = ColourBase();
}
Is that good or is the memory space then not allocated? I've read that the "new" is not supported. I looked in this forum post:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1216134904
and try to include the code, but I get a multiple definition error (so I suppose its already somewhere, but where?).

I try to refer to the ColourBase objects in a function like this:
Code:
calculateShadeTint(cArray[i]);  // call to function and passing the object

void ColourPalette::calculateShadeTint(ColourBase c)
{
  c.tintHSBColor[0] = c.wheelHSBColor[0];
  c.tintHSBColor[1] = 255;
  c.tintHSBColor[2] = 255;
}

What do I do wrong?




29  Using Arduino / Programming Questions / Re: a pointer to a multidimensional array on: September 21, 2011, 03:49:15 am
Completely clear now. Thanks for the effort explaining it.
30  Using Arduino / Programming Questions / Re: a pointer to a multidimensional array on: September 20, 2011, 11:59:47 am
Yes, using pointers is still hard to grasp for me, thank your for the clear metaphor.

Quote
You are defining an array, but that array is local in scope (limited to the constructor) and lifetime (it goes away when the constructor ends).

So I have to do this in the .h file in the public section of the class?
Code:
int wheelHSBColor[3];

And for the cArray:
Code:
ColourBase cArray[6];

I thought I couldn't initialize anything in the .h files, but I think I was wrong?
Pages: 1 [2] 3 4 5