Loading...
  Show Posts
Pages: 1 2 [3] 4 5
31  Using Arduino / Programming Questions / Re: a pointer to a multidimensional array on: September 19, 2011, 12:37:01 pm
Yes, but if I try that then I get this error:

Code:
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight.cpp:55: error: cannot convert 'int [25][3]' to 'int**' in assignment

I tried this as well:
Code:
rybWheel = &_rybWheel;

error: /Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight.cpp:55: error: cannot convert 'int (*)[25][3]' to 'int**' in assignment

Pointer is still a hard subject to grab for me.
32  Using Arduino / Programming Questions / a pointer to a multidimensional array on: September 19, 2011, 11:23:28 am
I'm trying to make a pointer to a multidimensional array. Any idea how to do that?

In my old post I already found out how to do that with one array.
http://arduino.cc/forum/index.php/topic,53807.0.html

My code.
Code:
int _rybWheel[25][3] =
{ { 0  , 255, 255 }, // 0
{ 12 , 255, 255 }, // 15
{ 24 , 255, 255 }, // 30
{ 30 , 255, 255 }, // 45
{ 36 , 255, 255 }, // 60
{ 42 , 255, 255 }, // 75
{ 48 , 255, 255 }, // 90
{ 54 , 255, 255 }, // 105
{ 60 , 255, 255 }, // 120
{ 72 , 255, 255 }, // 135
{ 84 , 255, 255 }, // 150
{ 108, 255, 255 }, // 165
{ 120, 255, 255 }, // 180
{ 154, 255, 255 }, // 195
{ 180, 255, 255 }, // 210
{ 206, 255, 255 }, // 225
{ 225, 255, 255 }, // 240
{ 240, 255, 255 }, // 255
{ 260, 255, 255 }, // 270
{ 265, 255, 255 }, // 285
{ 280, 255, 255 }, // 300
{ 300, 255, 255 }, // 315
{ 315, 255, 255 }, // 330
{ 333, 255, 255 }, // 345
{ 360, 255, 255 }  // 360 
};


I declare the array in the .h file like this:
Code:
int* rybWheel;

And in the constructor I write.
Code:
rybWheel = _rybWheel;

And I do this in a function (thats the error on line 360)
Code:
Serial.println(rybWheel[rybWheelIndex+1][0],DEC);

I get these errors:
Code:
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight.cpp: In constructor 'ColourPalette::ColourPalette()':
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight.cpp:55: error: cannot convert 'int [25][3]' to 'int*' in assignment
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight.cpp: In member function 'void ColourPalette::ColourAtRYBWheel(int, int*)':
/Users/macbook/Dropbox/code/_arduino/libraries/ColorLight/ColorLight.cpp:360: error: invalid types 'int[int]' for array subscript

I've looked up some information on pointers, but I cannot find clear information about pointers to multidimensional arrays and how I can use that with Arduino.
33  Using Arduino / Programming Questions / Re: bit math problem - left and right shift rgb color on: September 18, 2011, 02:17:27 am
Thank you. That works! I forgot about intermediate result.
34  Using Arduino / Programming Questions / bit math problem - left and right shift rgb color on: September 17, 2011, 12:56:49 pm
I try to store RGB color in an unsigned long (I think thats 4 bytes on Arduino).

I've based my code on two examples from Processing:
http://processing.org/reference/rightshift.html
http://processing.org/reference/leftshift.html

If I do this 255 << 8 I get a a hex code #FFFF00, while I expect #00FF00.
It seems kind of strange to me, but maybe I miss something essential?

Below the code that I use to debug.

Code:
//http://processing.org/reference/rightshift.html
//http://processing.org/reference/leftshift.html

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

void loop()
{ byte inputr = 0;
  byte inputg = 255;
  byte inputb = 0;
 
  Serial.print("input r: ");
  Serial.print(inputr,DEC);
  Serial.print(" input g: ");
  Serial.print(inputg,DEC);
  Serial.print(" input b: ");
  Serial.println(inputb,DEC);
 
  unsigned long c = inputr << 16 | inputg << 8 | inputb;
 
  Serial.print("output HEX: ");
  Serial.println(c,HEX);
  //Serial.print("output BIN: ");
  //Serial.println(c,BIN);
   
  byte r = (c >> 16) & 0xFF; 
  byte g = (c >> 8) &  0xFF; 
  byte b = c & 0xFF;       
 
  Serial.print("r: ");
  Serial.print(r,DEC);
 
  Serial.print(" g: ");
  Serial.print(g,DEC);
 
  Serial.print(" b: ");
  Serial.println(b,DEC);
 
  Serial.println("====================");
  delay(500); 
}
35  Development / Other Software Development / Re: problem with array in library on: February 28, 2011, 01:02:51 pm
Clear. In my other examples i've used the byte type for this.

I've put the library online in my blog:
http://www.kasperkamperman.com/blog/arduino-moodlight-library/

If there are any issues please let my know.
36  Development / Other Software Development / Re: problem with array in library on: February 28, 2011, 11:32:25 am
Thanks this works. However I still wonder why I couldn't use the global array directly?

After you're example I tried it in my old way, and it works.

Probably this int dc[256] was the issue. I forgot to set the length of the array..

Whats the benefit to make the type in an unsigned int ? : uint8_t
37  Development / Other Software Development / Re: problem with array in library on: February 28, 2011, 07:11:13 am
Hi,

Here the library in the zip-file. In the example the debugging code :
http://dl.dropbox.com/u/1147392/MoodLight.zip

@Coding Badly

if I do this :
var test = ml._dim_curve[254];
Serial.println(test);

I expect to see: 248 (the value on index number 254).

I get back a lot of zero's or other strange numbers that aren't in the array.
Putting the array in my 'normal' code works perfectly.

@robtillaart.
I've made the array public (as you can see in the example) but I get the same broken value's.


38  Development / Other Software Development / problem with array in library on: February 28, 2011, 04:05:28 am
Hi,

I'm trying to make an Arduino library with the tutorial. http://www.arduino.cc/en/Hacking/LibraryTutorial. The only thing that doesn't work is to use an Array. I don't get compile errors, but the values that I get back don't seem to come from the array. Probably its something with a pointer, but I've no idea how to solve that.

The problem is in the _dim_curve[] array, that I'd like to use as a lookup table. That works perfect in a normal Arduino sketch (http://www.kasperkamperman.com/blog/arduino/arduino-programming-hsb-to-rgb/), but in the library that doesn't work.

My .cpp code:

Code:
#include "WProgram.h"
#include "MoodLight.h"

MoodLight::MoodLight()
{
 
}


int _dim_curve[] = {
    0,   1,   1,   2,   2,   2,   2,   2,   2,   3,   3,   3,   3,   3,   3,   3,
    3,   3,   3,   3,   3,   3,   3,   4,   4,   4,   4,   4,   4,   4,   4,   4,
    4,   4,   4,   5,   5,   5,   5,   5,   5,   5,   5,   5,   5,   6,   6,   6,
    6,   6,   6,   6,   6,   7,   7,   7,   7,   7,   7,   7,   8,   8,   8,   8,
    8,   8,   9,   9,   9,   9,   9,   9,   10,  10,  10,  10,  10,  11,  11,  11,
    11,  11,  12,  12,  12,  12,  12,  13,  13,  13,  13,  14,  14,  14,  14,  15,
    15,  15,  16,  16,  16,  16,  17,  17,  17,  18,  18,  18,  19,  19,  19,  20,
    20,  20,  21,  21,  22,  22,  22,  23,  23,  24,  24,  25,  25,  25,  26,  26,
    27,  27,  28,  28,  29,  29,  30,  30,  31,  32,  32,  33,  33,  34,  35,  35,
    36,  36,  37,  38,  38,  39,  40,  40,  41,  42,  43,  43,  44,  45,  46,  47,
    48,  48,  49,  50,  51,  52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,
    63,  64,  65,  66,  68,  69,  70,  71,  73,  74,  75,  76,  78,  79,  81,  82,
    83,  85,  86,  88,  90,  91,  93,  94,  96,  98,  99,  101, 103, 105, 107, 109,
    110, 112, 114, 116, 118, 121, 123, 125, 127, 129, 132, 134, 136, 139, 141, 144,
    146, 149, 151, 154, 157, 159, 162, 165, 168, 171, 174, 177, 180, 183, 186, 190,
    193, 196, 200, 203, 207, 211, 214, 218, 222, 226, 230, 234, 238, 242, 248, 255,
};

void MoodLight::setHSB(int hue, int sat, int val) {
  /* convert hue, saturation and brightness ( HSB/HSV ) to RGB
     The dim_curve is used only on brightness/value and on saturation (inverted).
     This looks the most natural.     
  */
 
  val = _dim_curve[val];
  Serial.println(val);
  //sat = 255-_dim_curve[255-sat];
 
  int r;
  int g;
  int b;
  int base;
 
  if (sat == 0) { // Acromatic color (gray). Hue doesn't mind.
 
    _red   = val;
    _green = val;
    _blue  = val;
   
  } else  {
   
    base = ((255 - sat) * val)>>8;
 
    switch(hue/60) {
case 0:
r = val;
g = (((val-base)*hue)/60)+base;
b = base;
break;

case 1:
r = (((val-base)*(60-(hue%60)))/60)+base;
g = val;
b = base;
break;

case 2:
r = base;
g = val;
b = (((val-base)*(hue%60))/60)+base;
break;

case 3:
r = base;
g = (((val-base)*(60-(hue%60)))/60)+base;
b = val;
break;

case 4:
r = (((val-base)*(hue%60))/60)+base;
g = base;
b = val;
break;

case 5:
r = val;
g = base;
b = (((val-base)*(60-(hue%60)))/60)+base;
break;
    }
     
    _red   = r;
    _green = g;
    _blue  = b;
  }   

}

int MoodLight::getRed(){

  return _red;

}

int MoodLight::getGreen(){

  return _green;

}

int MoodLight::getBlue(){

  return _blue;

}


And in the .h

Code:
#ifndef MoodLight_h
#define MoodLight_h

#include "WProgram.h"

class MoodLight
{
  public:
    MoodLight();
    void setHSB(int,int,int);
    int getRed();
    int getGreen();
    int getBlue();
   
  private:
    int _dim_curve[];
    //int _getCurve(int);
    int  _red;
    int  _green;
    int  _blue;
};

#endif
39  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Problem with 0017, Firmata 2.1 on Duemilanove on: September 24, 2009, 08:09:29 am
I use as3glue with Firmata 2.1 Changing the serialspeed ( in serproxy ) worked out good ( thanks for the tip ) and I have connection.

However I have also problems with the analog inputs. They don't give a range from 0-1023 anymore ( over a even range of 0-5V with a potmeter ). This is a software problem, because with Firmata 2.0 it works good.

Changing the firmata.cpp and firmata.h in the Arduino 17 library's folder didn't work either.

In the forum someone made his on changes :
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1253735359/0

Those work, but the serialspeed is different.

Since I use it in an educational situation it would be good that a standard becomes kind of a standard. I hope Arduino 18 can come with a stable version.
40  Forum 2005-2010 (read only) / Syntax & Programs / Re: array of array variable names on: August 29, 2010, 03:39:35 am
Thanks to all for the tips. Thanks Dave for giving the idea of putting all the sizes in a separate array. In the end I did it without defining a struct.

Code:
int categorie1[]  = {1 };
int categorie2[]  = {1, 2 };
int categorie3[]  = {3, 4, 5 };
int categorie4[]  = {4, 8, 3, 11 };
int categorie5[]  = {2, 4, 8, 3, 15 , 11, 12, 13 };
int categorie6[]  = {1, 2, 8, 12, 6 };
int categorie7[]  = {20, 1, 15 };
int categorie8[]  = {2, 4, 8 };
int categorie9[]  = {2, 6 };
int categorie10[] = {2 };

int * categorieArray[10] = { categorie1, categorie2, categorie3,
                             categorie4, categorie5, categorie6,
                             categorie7, categorie8, categorie9,
                             categorie10 };

int categorieSizeArray[] =
{ sizeof(categorie1) / sizeof(int),
  sizeof(categorie2) / sizeof(int),
  sizeof(categorie3) / sizeof(int),
  sizeof(categorie4) / sizeof(int),
  sizeof(categorie5) / sizeof(int),
  sizeof(categorie6) / sizeof(int),
  sizeof(categorie7) / sizeof(int),
  sizeof(categorie8) / sizeof(int),
  sizeof(categorie9) / sizeof(int),
  sizeof(categorie10) / sizeof(int),
};

void setup()
{ Serial.begin(57600);
  
  for (int i=0; i < 10; i++)
  { // print category number
    Serial.print("category :");
    Serial.println(i+1);
    
    // print the contents of each category
    for (int j=0; j < categorieSizeArray[i]; j++)
    { Serial.println(categorieArray[i][j]);
    }  
  }
  
}


void loop()
{  
}


41  Forum 2005-2010 (read only) / Syntax & Programs / array of array variable names on: August 28, 2010, 08:45:07 am
Hi,

I would like to create an array with arraynames. I've already read something about pointers in another topic. That code seems to work good with ints. However with array I get this error:

error: cannot convert 'int (*)[1]' to 'int*' in initialization

Code:
int categorie1[]  = {1 };
int categorie2[]  = {1, 2 };
int categorie3[]  = {3, 4, 5 };
int categorie4[]  = {4, 8, 3, 11 };
int categorie5[]  = {2, 4, 8, 3, 15 , 11, 12, 13 };
int categorie6[]  = {1, 2, 8, 12, 6 };
int categorie7[]  = {20, 1, 15 };
int categorie8[]  = {2, 4, 8 };
int categorie9[]  = {2, 6 };
int categorie10[] = {2 };

int * categorieArray[10] = { &categorie1, &categorie2, &categorie3, &categorie4 ,&categorie5, &categorie6, &categorie7, &categorie8, &categorie9, &categorie10 };

I would like to loop through the array in this way.
Code:
for (int i=0; i < 10; i++)
  { Serial.println(sizeof(categorieArray[i]) / sizeof(int));    
  }

Is it possible what I want ?
42  Forum 2005-2010 (read only) / Syntax & Programs / string to int (pwm) on: April 11, 2007, 06:09:24 am
I've posted this question also in the software interfacing part, but I think the problem is more on the Arduino hardware/software side.

I try to convert a string like from 000 to 255 to a value for the PWM output.
I use to method below, but sometimes other PWM outputs react on changes on another output.

Maybe the code isn't efficient enough.

Is there a way to convert string or hexicadecimal values ( 00-FF ) to an output value with the standard Arduino library ?
From string to int or someting.

Code:
if (serInString[0]==73)  // I
{ for (int i=1; i <= digseq; i++)
  { if (serInString[i]==',')
    { p++;
      i++;
      }    
    char valchar=serInString[i];
      if(p==8 || p==12 || p==13)                        // digital outputs
      { // other code      
      }
      else                                           // PWM outputs
      { valpwm = 0;
        valpwm = (serInString[i]-48)*100;
        valpwm = valpwm + (serInString[i+1]-48)*10;
        valpwm = valpwm + (serInString[i+2]-48);
      
        i=i+2;                                    
        analogWrite(p,valpwm);                   
      }
  }  
}
43  Forum 2005-2010 (read only) / Syntax & Programs / Re: Rainbow calculator on: April 19, 2007, 08:02:53 am
I was working on a HSV -> RGB function for the Arduino. In the code field below the result.
It seems the work when I watch the serial output, however I didn't test it with an RGB led.
This might be enough for a Rainbow ( change the hue ).

Any suggestions for improvement are welcome ( i'm more a designer than a programmer ).  

Code:
// based on <http://www.codeproject.com/miscctrl/CPicker.asp>
// I use 2 analog inputs
// Didn't test it with an RGB led, but the serial output seems alright.

long base;
long hue;
long sat;
long val;

int r;
int g;
int b;

int ana_0 = 0; // used for analog inputs
int ana_1 = 0; // used for analog inputs

void getRGB()
{
      if (sat == 0) // Acromatic color (gray). Hue doesn't mind.
      {   r = val;
          g = val;
          b = val;  
      }
      else
      {   base = ((255 - sat) * val)>>8; // >>8 same as dividing by 255
          
            switch(hue/60)
            {
            case 0:
                  r = val;
                  g = (((val-base)*hue)/60)+base;
                  b = base;
            break;

            case 1:
                  r = (((val-base)*(60-(hue%60)))/60)+base;
                  g = val;
                  b = base;
            break;

            case 2:
                  r = base;
                  g = val;
                  b = (((val-base)*(hue%60))/60)+base;
            break;

            case 3:
                  r = base;
                  g = (((val-base)*(60-(hue%60)))/60)+base;
                  b = val;
            break;

            case 4:
                  r = (((val-base)*(hue%60))/60)+base;
                  g = base;
                  b = val;
            break;

            case 5:
                  r = val;
                  g = base;
                  b = (((val-base)*(60-(hue%60)))/60)+base;
            break;
            }
            colorsRGB[0]=r;
            colorsRGB[1]=g;
            colorsRGB[2]=b;
      }  
}

void setup()
{ digitalWrite(13, HIGH);
  Serial.begin(9600);  
}

void loop()  
{ ana_0 = analogRead(0); // # between 0-1023
  ana_1 = analogRead(1); // # between 0-1023
    
  hue=(360*(long)ana_0)>>10; //0-360; //shift bits = /1023
  sat=ana_1>>2;                    //0-255;    
  val=255;                            //0-255;
  
  getRGB();
  
  Serial.println(colorsRGB[0]);
  Serial.println(colorsRGB[1]);
  Serial.println(colorsRGB[2]);  
  delay(100);
}
44  Forum 2005-2010 (read only) / Syntax & Programs / Re: return an array from a function on: April 20, 2007, 03:09:54 pm
Ok, this works. I thought you always had to return someting to put a value into an array.

Would you mind to explain me how this works ( just curious ) ? How gets the data into the colors1 array ? Does it have to do with the fact that an array is a kind of a pointer ?
45  Forum 2005-2010 (read only) / Syntax & Programs / return an array from a function on: April 19, 2007, 05:03:06 pm
I want to return an array from a function. But I get the follow error :
In function 'int getRGB()':
error: invalid conversion from 'int*' to 'int' In function 'void loop()':

Writing : int getRGB()[3] doesn't seem to work :
error: 'getRGB' declared as function returning an array In function 'int getRGB()':

I searched in the forum but couldn't find a syntax for it.

Code example :

Code:
int colorsRGB[3];
int colors_1[3];
int colors_2[3];

int getRGB()
{ colorsRGB[0]=255;
   colorsRGB[1]=0;
   colorsRGB[2]=0;  
   return colorsRGB;
}

colors_1=getRGB();
colors_2=getRGB();



Pages: 1 2 [3] 4 5