Show Posts
Pages: 1 2 3 [4] 5
46  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 ?
47  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);                   
      }
  }  
}
48  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);
}
49  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 ?
50  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();



51  Forum 2005-2010 (read only) / Syntax & Programs / Re: bit shifting unsigned long on: April 19, 2007, 02:06:13 pm
Thank you, that solved the problem.
52  Forum 2005-2010 (read only) / Syntax & Programs / bit shifting unsigned long on: April 19, 2007, 08:30:08 am
Hi,

I've a problem with bitshifting values. According to the reference a long can story 32 bit ( 4 bytes ). I would like to store an RGB value ( 3 bytes ) in a long, with bitshifting.

However, shifting 1 bit higher than 14 bits ( 1 << 15 ) doesn't seem to work.

I've made a test application, code below.
color_in and colour_out should output the same value (1), but this goes wrong when ana_0 is above 14 ( shifting with 14 bits ).

Code:
unsigned long ana_0;

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

void loop()  
{ ana_0 = analogRead(0)>>5; // # between 0-32
      
  unsigned long color_in  = 1 << ana_0;
  unsigned long color_out = color_in >> ana_0;
  
  Serial.println(ana_0);
  Serial.println(color_in);
  Serial.println(color_out);
  
  delay(100);
}

53  Forum 2005-2010 (read only) / Interfacing / Re: Flash + Arduino on: January 04, 2011, 05:11:22 am
@theMPloc I've no idea, think this is hardware related.
54  Forum 2005-2010 (read only) / Interfacing / Re: Flash + Arduino on: January 04, 2011, 03:55:31 am
The Firmata included with Arduino 0022 works good with the Arduino UNO (version 0021 not), so thats the solution.
You can upload Standard Firmata.
55  Forum 2005-2010 (read only) / Interfacing / Re: Flash + Arduino on: December 22, 2010, 08:48:12 am
Nope. No idea how to solve this  smiley-sad I think its related to the new serialchip of the Arduino UNO. Anyone who has a clue please post in this topic:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1291826044
56  Forum 2005-2010 (read only) / Interfacing / Re: Flash + Arduino on: December 08, 2010, 11:38:17 am
I've made 2 tutorials on this issue. Also to be find in the playground.

I use the Messenger library to do some error detection on strings.

http://www.kasperkamperman.com/blog/arduino-flash-communication-as3-messenger/

http://www.kasperkamperman.com/blog/arduino/arduino-flash-communication-as3/
57  Forum 2005-2010 (read only) / Interfacing / Re: Scratch Library on: October 12, 2010, 12:31:28 pm
For the overview :
I've found another implementation as well from Yengawa systems.

Here the translated site :
http://translate.google.com/translate?js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&sl=auto&tl=en&u=http%3A%2F%2Fwww.yengawa.com%2Fscratch_arduino&act=url

You have to upload the .pde. The button pin is on digital pin 2 (more logical in my opinion, so you keep RX/TX free).

Next to this you can also program the arduino in a scratch way.
Scratch for Arduino : http://seaside.citilab.eu/scratch/arduino
and modkit : http://www.modk.it/
58  Forum 2005-2010 (read only) / Interfacing / Re: Scratch Library on: October 12, 2010, 12:14:36 pm
Nice library. Does the button only work with the internal Pull-up resistor ? I would like to connect the button with a 10K resistor (pull-down). Because I'm teaching with it, I like to explain that part of electronics as well.
59  Forum 2005-2010 (read only) / Interfacing / Re: Unity3d + Arduino (Read serial in Unity3d) on: May 12, 2010, 04:14:01 pm
Here you can find some Unity-Arduino examples. Doesn't work on osx yet, suggestions are welcome.

http://code.google.com/p/unity-arduino-serial-connection/
60  Forum 2005-2010 (read only) / Interfacing / Re: Using Arduino Diecimila as a PC mouse on: September 26, 2007, 10:04:20 am
I was wondering. Wouldn't it be possible to use Arduino with a serialmouse driver. I've found a serialdriver from a pen tablet.
http://www.aiptek.com/drivers.htm#hp6u

Couldn't Arduino output information in that protocol ?
And if its possible, how do you know what the protocol is ? Would it be possible to analyse the output with a serial monitor from such a device ?

Anyone has an idea how a serial mouse on RS232 worked ?
Or is using the MouseWarrior to let Arduino spit out HID/mouse data the only way ?
Pages: 1 2 3 [4] 5