Show Posts
Pages: [1] 2
1  Forum 2005-2010 (read only) / Syntax & Programs / Re: Programming an arduino (newbie) on: November 09, 2010, 08:49:05 am
once you resolved the real life kicks problem,

you will also need the following in your arduino program

millis()

http://www.arduino.cc/en/Reference/Millis

best
2  Forum 2005-2010 (read only) / Syntax & Programs / Re: a strange thing is happening on: November 10, 2010, 09:57:07 am
Hi! thanks for your feedback.

I realized that the whole thing can de done easily with structures. I post the code if someone have also this trouble.




Code:

struct pi_col {
unsigned col:
  12;
};

struct pi_led {
  pi_col r;
  pi_col g;
  pi_col b;
};

struct pi_row {
  pi_led led[8];
};

pi_row bi_row;



Quote
And with "struct pi_row_led_col {  unsigned  data:12; };" you're being misled as this is in reality occupying 16-bits, the sizeof(int) which is the default data type when specifying just "unsigned" as the data type.

Verify by printing the sizeof(pi_row_led_col)!

I also had my doubts but I tested the method and is working fine... sizeof returns 2 because sizeof returns the number of bytes as an integer and 12 bits make 1.5 byte. I tried with an struct which had 2x12bits = 24bits and sizeof returned 3...

thanks for your help.
3  Forum 2005-2010 (read only) / Syntax & Programs / Re: a strange thing is happening on: November 09, 2010, 01:51:49 pm

hi,

when the object is constructed the size of the array is define through the variable pi_row_len, this means that the array size is == pi_row_len. I'm wrong??

I removed the pointer and kept getting a smaller mistake...

0.  .0.  .1.  .END
0.  .C.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END

thanks!!!

4  Forum 2005-2010 (read only) / Syntax & Programs / a strange thing is happening on: November 09, 2010, 01:29:24 pm
hi there!

I'm having a strange phenomenon with a struct and two classes which contain it.

All the variables are supposed to have the same value (0), however when I print them I get some mistakes with a specific pattern...

0.  .129.  .131.  .END
135.  .14A.  .141.  .END
147.  .14D.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END

the next iteration:

C69.  .129.  .F71.  .END
135.  .10A.  .141.  .END
147.  .14D.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END
0.  .0.  .0.  .END



did i reach a bottleneck? or there could be a solution for this?

very strange...  :-/


here is the code:


main
Code:
#include "pi_classes.h"

pi_row bi_row(8);


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

void loop(){
  
  bi_row.row_prtdat();
  Serial.println("  ");
  delay(20000);

}


pi_classes.cpp

Code:
#include "pi_classes.h"

pi_row_led::pi_row_led(pi_row_led_col led_in_r, pi_row_led_col led_in_g, pi_row_led_col led_in_b){
  
  led_r.cdata = led_in_r.cdata;
  led_g.cdata = led_in_g.cdata;
  led_b.cdata = led_in_b.cdata;
  
}

void pi_row_led::change_r(pi_row_led_col led_in_r) { led_r.cdata = led_in_r.cdata; }
void pi_row_led::change_g(pi_row_led_col led_in_g) { led_g.cdata = led_in_g.cdata; }
void pi_row_led::change_b(pi_row_led_col led_in_b) { led_b.cdata = led_in_b.cdata; }

pi_row_led_col pi_row_led::get_r() { return led_r; }
pi_row_led_col pi_row_led::get_g() { return led_g; }
pi_row_led_col pi_row_led::get_b() { return led_b; }


// *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .*


pi_row::pi_row (byte pi_row_len_in) {
  
  pi_row_len = pi_row_len_in;
  
  pi_row_led_col col_tmp;
  col_tmp.cdata = 0;
  
  row_pix[pi_row_len];
  row_pix_pnt[pi_row_len];
  for (byte i = 0; i < pi_row_len; i++) {
    
    row_pix_pnt[i] = &row_pix[i];
    row_pix[i].change_r(col_tmp);
    row_pix[i].change_g(col_tmp);
    row_pix[i].change_b(col_tmp);    
    
  }
  
}

void pi_row::row_prtdat() {
  
    for (byte i = 0; i < pi_row_len; i++) {
      
    Serial.print(row_pix[i].get_r().cdata, HEX);
    Serial.print(".  .");
    Serial.print(row_pix[i].get_g().cdata, HEX);
    Serial.print(".  .");
    Serial.print(row_pix[i].get_b().cdata, HEX);
    Serial.println(".  .END");
    
  }
  
}


classes.h

Code:
#include <WProgram.h>

struct pi_row_led_col {
  unsigned cdata:12;
};

class pi_row_led {

  public:

  pi_row_led(pi_row_led_col led_in_r, pi_row_led_col led_in_g, pi_row_led_col led_in_b);
  void change_r(pi_row_led_col led_in_r);
  void change_g(pi_row_led_col led_in_g);
  void change_b(pi_row_led_col led_in_b);

  pi_row_led_col get_r();
  pi_row_led_col get_g();
  pi_row_led_col get_b();
  
  private:

  pi_row_led_col led_r;
  pi_row_led_col led_g;
  pi_row_led_col led_b;

};


// *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .*


class pi_row {
  
  public:
  
  pi_row(byte pi_row_len_in);
  byte pi_row_len;
  void row_prtdat();

  private:
  pi_row_led row_pix[];
  pi_row_led *row_pix_pnt[];
  
};

5  Forum 2005-2010 (read only) / Syntax & Programs / Re: 12 bit variable on: November 09, 2010, 08:37:48 am
Hi,

I realized that the memory corruption occurs when I construct the variables. (this section is commented and red now).

 I don't have a clue to be honest. Have anybody an idea of what is happening?

if you need the rest of the program, tell me... it is pretty long but I can post it as well.

thx a lot

pi_classes.h
Code:

#include <WProgram.h>

struct pi_row_led_col {
  unsigned cdata:12;
};

struct pi_row_led_col_rgb {
  pi_row_led_col r;
  pi_row_led_col g;
  pi_row_led_col b;
};




class pi_row_led {

  public:

  pi_row_led(pi_row_led_col led_in_r, pi_row_led_col led_in_g, pi_row_led_col led_in_b);
  void change_r(pi_row_led_col led_in_r);
  void change_g(pi_row_led_col led_in_g);
  void change_b(pi_row_led_col led_in_b);

  pi_row_led_col get_r();
  pi_row_led_col get_g();
  pi_row_led_col get_b();
  
  private:

  pi_row_led_col led_r;
  pi_row_led_col led_g;
  pi_row_led_col led_b;

};


// *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .*


class pi_row {
  
  public:
  
  pi_row(byte pi_row_len_in);
  byte pi_row_len;
  void row_prtdat();

  private:
  pi_row_led row_pix[];
  pi_row_led *row_pix_pnt[];
  
};


pi_classes.cpp

Code:
#include "pi_classes.h"


pi_row_led::pi_row_led(pi_row_led_col led_in_r, pi_row_led_col led_in_g, pi_row_led_col led_in_b){
  
  led_r.cdata = led_in_r.cdata;
  led_g.cdata = led_in_g.cdata;
  led_b.cdata = led_in_b.cdata;
  
}

void pi_row_led::change_r(pi_row_led_col led_in_r) { led_r.cdata = led_in_r.cdata; }
void pi_row_led::change_g(pi_row_led_col led_in_g) { led_g.cdata = led_in_g.cdata; }
void pi_row_led::change_b(pi_row_led_col led_in_b) { led_b.cdata = led_in_b.cdata; }

pi_row_led_col pi_row_led::get_r() { return led_r; }
pi_row_led_col pi_row_led::get_g() { return led_g; }
pi_row_led_col pi_row_led::get_b() { return led_b; }


// *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .*


pi_row::pi_row (byte pi_row_len_in) {
  
  pi_row_len = pi_row_len_in;
  
  //pi_row_led_col col_tmp;  
  //col_tmp.cdata = 2047;
  
  //row_pix[pi_row_len];  // >>>> here occurs data corruption!!!
  //row_pix_pnt[pi_row_len];  // >>>> here occurs data corruption!!!

  for (byte i = 0; i < pi_row_len; i++) {
    
    //row_pix_pnt[i] = &row_pix[i];
    //row_pix[i].change_r(col_tmp);
    //row_pix[i].change_g(col_tmp);
    //row_pix[i].change_b(col_tmp);    
    
  }
  
}

void pi_row::row_prtdat() {
  
    for (byte i = 0; i < pi_row_len; i++) {
    
    //pi_row_led_col col_tmp;
    //col_tmp.cdata = row_pix[i].get_r().cdata;  
      
    Serial.print(row_pix[i].get_r().cdata, HEX);
    Serial.print(".  .");
    Serial.print(row_pix[i].get_g().cdata, HEX);
    Serial.print(".  .");
    Serial.print(row_pix[i].get_b().cdata, HEX);
    Serial.println(".  .");
    
  }
  
}


6  Forum 2005-2010 (read only) / Syntax & Programs / Re: 12 bit variable on: November 09, 2010, 07:54:02 am
thanks for your help!!!

the solution worked, but: it affected other regions of the memory...  :o, it is very strange...

I created the structure "color" and then I created a class "pixel" which contains three of this structures. Another class "row" contains 8 "pixels"
when I assing the values to the "colors" contained in "pixels" of the "row" the arduino does not assing correctly the values of the  "colors" and the values of completely unrelated variables are changed.  :'(

do you think that using pointers will solve the trouble???

many many thanks for your help. (code follows.)

pi_classes.h

Quote

#include <WProgram.h>

struct pi_row_led_col {
  unsigned data:12;
};

struct pi_row_led_col_rgb {
  pi_row_led_col r;
  pi_row_led_col g;
  pi_row_led_col b;
};

class pi_row_led {

  public:

  pi_row_led(pi_row_led_col led_in_r, pi_row_led_col led_in_g, pi_row_led_col led_in_b);
  void change_r(pi_row_led_col led_in_r);
  void change_g(pi_row_led_col led_in_g);
  void change_b(pi_row_led_col led_in_b);

  pi_row_led_col get_r();
  pi_row_led_col get_g();
  pi_row_led_col get_b();
  
  private:

  pi_row_led_col led_r;
  pi_row_led_col led_g;
  pi_row_led_col led_b;

}; 


// *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .*

class pi_row {
  
  public:
  
  pi_row(byte pi_row_len_in);
  byte pi_row_len;
  void row_prtdat();

  private:
  pi_row_led row_pix[];
  
};


pi_classes.cpp

Quote
#include "pi_classes.h"


pi_row_led::pi_row_led(pi_row_led_col led_in_r, pi_row_led_col led_in_g, pi_row_led_col led_in_b){
  
  led_r.data = led_in_r.data;
  led_g.data = led_in_g.data;
  led_b.data = led_in_b.data;
  
}

void pi_row_led::change_r(pi_row_led_col led_in_r) { led_r.data = led_in_r.data; }
void pi_row_led::change_g(pi_row_led_col led_in_g) { led_g.data = led_in_g.data; }
void pi_row_led::change_b(pi_row_led_col led_in_b) { led_b.data = led_in_b.data; }

pi_row_led_col pi_row_led::get_r() { return led_r; }
pi_row_led_col pi_row_led::get_g() { return led_g; }
pi_row_led_col pi_row_led::get_b() { return led_b; }


// *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .*


pi_row::pi_row (byte pi_row_len_in) {
  
  pi_row_len = pi_row_len_in;
  
  pi_row_led_col col_tmp;
  col_tmp.data = 2047;
  
  row_pix[pi_row_len];
  for (byte i = 0; i < pi_row_len; i++) {
    
    row_pix.change_r(col_tmp);
    row_pix.change_g(col_tmp);
    row_pix.change_b(col_tmp);    
    
  }
  
}

void pi_row::row_prtdat() {
  
    for (byte i = 0; i < pi_row_len; i++) {
    
    //pi_row_led_col col_tmp;
    //col_tmp.data = row_pix.get_r().data;  
      
    Serial.print(row_pix.get_r().data, HEX);
    Serial.print(".  .");
    Serial.print(row_pix.get_g().data, HEX);
    Serial.print(".  .");
    Serial.print(row_pix.get_b().data, HEX);
    Serial.println(".  .");
    
  }
  
}

// *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .* *. .*


and this is what I get when Iuse the row_prtdat():

0.  .0.  .7FF.  .
7FF.  .7FF.  .7FF.  .
7FF.  .7FF.  .BFF.  .
700.  .8FF.  .7FF.  .
AFF.  .7FF.  .9FF.  .
7FF.  .7FF.  .7FF.  .
7FF.  .7FF.  .7FF.  .
7FF.  .7FF.  .7FF.  .
Transmitir........0.0.0.0.1.1.1.1.1.255.8.

there are incorrect values in the array and the numbers in red are normally 0 and 1. (!!!)

7  Forum 2005-2010 (read only) / Syntax & Programs / 12 bit variable on: November 08, 2010, 04:26:01 pm
Hi,

I'm trying to interface the arduino trough the classical latch, clock and data pins.

I already did this and I know how to do it. The problem is that the data that the chip needs is contained in blocks of 12 bits. This represents a problem as there are no suitable data types, what results in memory wasting and in complex conversions, i.e. shifting bits with the classical (1 << i) bit mask is not anymore so easy.

is it possible to create a 12 bit variable???

I found the following for C++:

http://www.cplusplus.com/reference/stl/bitset/operators/

but I see that it doesn't work in arduino... any ideas???
8  Forum 2005-2010 (read only) / Syntax & Programs / Another question with classes on: November 08, 2010, 12:54:21 pm
now that my first class (le_led) works  smiley-grin I would like to develop a second one which contains an array of objects of the first's class type.

I don't know exactly how to do it. What I want to create is an array of leds which contains 8 objects of the le_led class. I'm not sure how I should initialize the object within the array. (I post my try which doesn't work and the class le_led)

I'm very very thankful for your help smiley


>>>> le_line.h
Quote

#include <WProgram.h>
#include "le_led.h"

class le_row{
  
  public:
    le_row(int row_len);    
    le_led row_arr[];
};




>>>> le_line.cpp
Quote
#include "le_line.h"
#include "le_led.h"

le_row::le_row(int row_len){

  row_arr[row_len];
  for (int i=0; i<row_len; i++){
    row_arr
  }

}



****** le_led.h

Quote
//
//le_led.h
//
// Need to include Arduino core header WProgram.h so that typedef
// for byte is known
//
#include <WProgram.h>

class le_led
{
  public:
    le_led(byte led_in_r, byte led_in_g, byte led_in_b);
    void change_r(byte led_in_r);
    void change_g(byte led_in_g);
    void change_b(byte led_in_b);
    //void change(byte led_in, int led_rgb);
    byte get_r();
    byte get_g();
    byte get_b();
    //void get(int led_rgb);
  private:
    byte led_r;
    byte led_g;
    byte led_b;
}; 


*****

le_led.cpp

Quote
//
// le_led.cpp
//
// Include le_led.h so that class definition is known
//
#include "le_led.h"

le_led::le_led(byte led_in_r, byte led_in_g, byte led_in_b){
  
  led_r = led_in_r;
  led_g = led_in_g;
  led_b = led_in_b;
  
}

void le_led::change_r(byte led_in_r) { led_r = led_in_r; }
void le_led::change_g(byte led_in_g) { led_g = led_in_g; }
void le_led::change_b(byte led_in_b) { led_b = led_in_b; }

byte le_led::get_r() { return led_r; }
byte le_led::get_g() { return led_g; }
byte le_led::get_b() { return led_b; }

9  Forum 2005-2010 (read only) / Syntax & Programs / Re: problem with a class on: November 08, 2010, 11:59:42 am
it worked now thanks!!!!  smiley  smiley  smiley
10  Forum 2005-2010 (read only) / Syntax & Programs / Re: problem with a class on: November 08, 2010, 11:08:04 am
hi,

thanks for your help.

does this mean that every class in arduino should be a library???

I didn't that with #include as I thought that the tabs were automatically compiled...  smiley-sad

makes sense then to include a file that is already a tab??

"#include thefile.pde"

(please note the .pde)

11  Forum 2005-2010 (read only) / Syntax & Programs / problem with a class on: November 08, 2010, 08:55:19 am
Hi, I'm trying to make a class called le_led which will contain infos about a "pixel". I read the arduino tutorials and searched in the forums but I can't understand why it doesn't work.

My project have 4 files ("tabs") and the class is not declared in the main file. When I do the following in the main file:

le_led pixel01(byte(0), byte(0), byte(0));


I get the following error:

_04_Bi_Protocolo:49: error: 'le_led' does not name a type

I also noticed the the constructor takes a strange gray color.

Can somebody help me???  smiley-wink


Quote
class le_led
{
  public:
    le_led(byte led_in_r, byte led_in_g, byte led_in_b);
    void change_r(byte led_in_r);
    void change_g(byte led_in_g);
    void change_b(byte led_in_b);
    void change(byte led_in, int led_rgb);
    byte get_r();
    byte get_g();
    byte get_b();
    void get(int led_rgb);
  private:
    byte led_r;
    byte led_g;
    byte led_b;
};



le_led::le_led(byte led_in_r, byte led_in_g, byte led_in_b){
  
  led_r = led_in_r;
  led_g = led_in_g;
  led_b = led_in_b;
  
}

void le_led::change_r(byte led_in_r) { led_r = led_in_r; }
void le_led::change_g(byte led_in_g) { led_g = led_in_g; }
void le_led::change_b(byte led_in_b) { led_b = led_in_b; }

byte le_led::get_r() { return led_r; }
byte le_led::get_g() { return led_g; }
byte le_led::get_b() { return led_b; }

12  Forum 2005-2010 (read only) / Español / Re: páginas en español on: December 13, 2006, 09:52:07 am
Oye david me parecería interesante publicar también en arduino.es

La verdad es que no había notado que cualquiera puede hacerlo. Pronto enviaré mis datos  smiley
13  Forum 2005-2010 (read only) / Español / páginas en español on: November 14, 2006, 11:11:53 am
Primero que todo hola.

La intención de este hilo es crear una colección de páginas sobre el arduino en español, de manera que no toque buscar mil veces sitios que son difíciles de encontrar...

acá está el primero obviamente...

http://randomlab.net/taller_06/index.php/Taller/Arduino

Además esto fomentará la creación de más páginas en español, ya que se deduce que todos los que trabajan con arduino saben inglés, puesto que la gran mayoría de la documentación está en ese idioma...
14  Forum 2005-2010 (read only) / Español / Re: Aumentar alcance sensor infrarojos? on: December 26, 2006, 11:57:56 am
En primer lugar el receptor de tres patas debe ser un fototransistor que es algo más lento que el fotodiodo (el de dos patas), la verdad es aconsejable continuar con el fotodiodo porque es extremadamente rápido, lo digo por experiencia, he logrado que reciba pulsos de 5 ms.

El fotodiodo lo puedes combinar con un transitor 2N2222 de manera que tengas una diferencia de voltaje suficiente para transmitirlo en digital, como quieres.

Es que la página que en donde está el esquemático no me abre, pero según recuerdo está el fotodiodo a secas, lo aconsejable y verás que mejora mucho es combinarlo con el 2N2222.

y respecto del alineamiento, es cierto que el fotodiodo funciona con la luz de frente, una opción es ponerle un lente...


bueno y se me había olvidado este otro hilo, creo que será de gran ayuda,

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1151345130/0#0
15  Forum 2005-2010 (read only) / Español / Re: Aumentar alcance sensor infrarojos? on: December 22, 2006, 11:22:49 am
Si pudieses colgar algo más de información como el esquema del circuito y el programa que estás usando sería mejor.

Además ¿cuál señal es la que capta en cuando se encuentra a 1 cm?

Mi opinión, con los pocos datos, es que primero debes empezar con un emisor infrarojo que no sea el de un control remoto sino uno comprado, porque según entiendo, los controles tienen una señal modulada. Así podrás ademas controlar los datos que se envían porque si no sabes que es lo que se debe recibir, mucho menos se podrá encontrar el error.

un saludo.
Pages: [1] 2