Show Posts
Pages: 1 ... 69 70 [71] 72 73 ... 147
1051  Using Arduino / Programming Questions / Re: Problem with Arduino auto-generated function declarations on: May 14, 2013, 06:44:47 pm
Thanks. I'll do that or rearrange the order of function definitions to not need a declaration.

I would recommend putting the declaration in yourself, rather than moving the definitions around. Eventually you will get a combination that doesn't see one function, and can't be moved due to its own dependencies.

On a side note, below is how I pass most fixed sized arrays, it is functionally equivalent to your version except the compiler provides the array size rather than you having to hard code in values/defines.

Code:
template< unsigned N >
  void bad_fun( char (&arr)[ N ] )
    {
      Serial.print( "Array Size: " );
      Serial.println( N, DEC );
      return;
    }

//And you call it exactly the same:
bad_fun(char_arr);

Evidently somebody thinks so, or we wouldn't have been lumbered with it. Personally, I think it's a mistake. Done well, it would have been a bad idea because it means that C++ coding experience doesn't transfer to Arduino and vice versa. However, it wasn't done well. I'm looking forward to the day that the Arduino IDE provides an option to turn this nonsense off.

I agree, they should stick with the basic C++ principles and have people declare/include as necessary. The IDE doesn't apply its changes to any other sketch files, which gives me the impression that whoever designed the auto-gen feature assumed we would all mostly use single file sketch's. And even worse assuming people using multi file sketches won't be able to write the 'sketch' file properly.

I remember reading a couple of years ago how Arduino is designed to feel more like a simple scripting language for non-programmers and not once was C++ mentioned. It was only after a bit of investigation I found out I was able to use straight C++. ( FAQ and mission statements updated now. )

I think the whole notion of trying to dumb down C++ is flawed, and too much mention is put on C, everything is 100% C++ unless you explicitly use a *.c file.
1052  Using Arduino / Programming Questions / Re: Problem with Arduino auto-generated function declarations on: May 14, 2013, 05:16:54 pm
Placing the declaration at the top works fine: 'void bad_fun(char arr[bigerr+1]);'
I think the team already is well aware of this bug, it affects function prototypes with references (&) and square brackets.
Using structs/classes as arguments also fails due to the prototype being placed above the struct.
1053  Using Arduino / Programming Questions / Re: Problem Serial.available() = 0 on: May 14, 2013, 12:41:46 am
You need to send data to it for any other result. Serial.available() only returns the number of bytes in the receive buffer, not weather the serial functionality is available.
1054  Using Arduino / Programming Questions / Re: [HELP] Read hex value from array problem on: May 13, 2013, 12:46:40 am
There are functions provided in pgmspace.h which allow you to read different sizes of data.

Code:

uint32_t ReadData = pgm_read_dword(&hello_01_data[ index ] );

http://www.nongnu.org/avr-libc/user-manual/group__avr__pgmspace.html
1055  Using Arduino / Programming Questions / Re: [Problems] Passing multiple multidimensional arrays as parameter on: May 11, 2013, 05:45:53 am
your link seems dead. are the two variables still declared int:
Code:
int greenScreen[8][8];
int redScreen[8][8];

or are they declared as char arrays?
Code:
char greenScreen[8][8];
char redScreen[8][8];
1056  Using Arduino / Programming Questions / Re: Am i over thinking things ? on: May 11, 2013, 02:52:36 am
The wireless uses SPI, so as long as you don't intend to run it off the MCP23008, it should be fine.
Connecting the LED's is up to you, should be enough free pins to use a transistor setup, or that 2003 chip will probably do too.

If your app runs too slow, there are many things you can learn to improve the code.
1057  Using Arduino / Programming Questions / Re: code differences on: May 11, 2013, 12:11:43 am
Example 2 uses hard coded values, maybe a test case of what you'd expect of the first code modified for 3 servos.
By itself it is useless. Whereas example 1 allows a function to be called with different values.

Neither code does really anything apart from write text to the serial output.

What is it you want to achieve,
move servos?
print output to serial?
something else?
1058  Using Arduino / Programming Questions / Re: Need help with complex #define statement on: May 10, 2013, 10:23:17 pm
I would reccomend using fatlib16's class: http://arduino.cc/forum/index.php/topic,150325.msg1128634.html#msg1128634

This should combine the two though.
Code:
#define fWrite( _pin_, _state_ ) ( ( _pin_ < 16 ) ? fWriteA( _pin_, _state_ ) : fWriteB( _pin_, _state_ ) )

It is using the C/C++ pre-processor syntax. Search macros and defines.
1059  Using Arduino / Programming Questions / Re: How to make global variables accessible to libraries/classes? on: May 10, 2013, 08:45:02 am
You can use this method, it highlights multiple classes that use each other and globally accessible variables:

Globals.h
Code:
#ifndef HEADER_GLOBALS
  #define HEADER_GLOBALS
  extern char grid[ 8 ][ 8 ];
#endif

A.h
Code:
#ifndef HEADER_A
  #define HEADER_A

  #include "Globals.h"
  #include "B.h"

  class A{
    public:
      A();
    protected:
      friend class B;
  };
#endif

A.cpp
Code:
#include "A.h"

A::A(){
  return;
}

B.h
Code:
#ifndef HEADER_B
  #define HEADER_B

  #include "Globals.h"

  class B{
    public:
      B();
  };
#endif

B.cpp
Code:
#include "B.h"

B::B(){
  return;
}

Sketch:
Code:
#include "A.h"

char grid[ 8 ][ 8 ];

void setup(){}
void loop(){}

The sketch needs only include "A.h" due to A.h including B.h and Globals.h.
1060  Using Arduino / Programming Questions / Re: How to make global variables accessible to libraries/classes? on: May 10, 2013, 07:23:54 am
Quote
Now I am puzzled.  What gave you this idea?  The IDE doesn't enforce syntax, and the compiler is a C++ compiler.

The IDE blunders with a few things still, classes not working can be a side-effect. Use of user defined types usually indicates some use of references, if this is the case with ali250, then there is a solution at hand.

this code for example won't compile:

Code:
struct foo{
  int a;
  char b;
};

void setup(){}
void loop(){}

void foofunc( foo &f )
  {
    f.a = random( 0, 0xffff );
  }

The fix for this case is to add the function prototype below the struct.

Code:
void foofunc( foo &f );

If this is not the problem, you can still use classes in other files, and use the 'extern' keyword on variables you want to be seen across different files.

Globals suck though, even more as you want classes to access them. The variables are probably better off as static members of the classes or in interfaces themselves ( static members of their own class, say "configuration" class )
1061  Using Arduino / Programming Questions / Re: Issue including EEPROM.h function calls within class on: May 09, 2013, 10:38:59 pm
This code works under IDE 1.0.4

make sure you have "#include <EEPROM.h>" in the sketch ( not just library ).
1062  Using Arduino / Programming Questions / Re: Interrupts and variables as arguments on: May 09, 2013, 10:27:23 pm
Leave the volatile modifier on, and you get the effects of 'volatile'

Code:
void callByReference( volatile int &x );
void callByPointer( volatile int *x );
1063  Using Arduino / Programming Questions / Re: TEA encryption algorithm test vector on: May 09, 2013, 08:18:58 pm
Are you sure your versions of the code are correct? this cypher works on 2x32 bit values, or a 64-bit block. Whereas your functions take 2x16 bit values and:

Code:
unsigned int delta=0x9e3779b9;

0x9e3779b9 is too large for the integer type.

Code:
for (i=0; i < 32; i++) {

This line is the same as the 64-bit version, I'd imagine yours would have half the iterations.
1064  Using Arduino / Programming Questions / Re: Reduce Uno RAM usage on: May 08, 2013, 01:29:19 pm
Quote
I'm no expert by any means, but I'm not sure it's a good idea using flash memory.

The flash memory is only changed when you upload a sketch, you may be thinking of the EEPROM, which has 10x more writes than the flash, but still has a limit.
1065  Using Arduino / Programming Questions / Re: Fiddling with pointers - casting on: May 08, 2013, 01:25:24 pm
This should work.

Code:
write( ( char* ) ptr );

Why not just use char* type instead of the unnecessary long.
Pages: 1 ... 69 70 [71] 72 73 ... 147