Show Posts
Pages: 1 ... 72 73 [74] 75 76 ... 150
1096  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
1097  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];
1098  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.
1099  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?
1100  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.
1101  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.
1102  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 )
1103  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 ).
1104  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 );
1105  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.
1106  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.
1107  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.
1108  Using Arduino / Programming Questions / Re: Reduce Uno RAM usage on: May 08, 2013, 01:01:16 pm
When you use the regular version, it is still stored in flash. When the MCU starts the global data section is initialised by copying the flash contents into ram.
The progmem features have a little overhead, but when used multiple times to replace ram data, it can produce smaller code like you see.
1109  Using Arduino / Programming Questions / Re: Long to Char Array and Back on: May 08, 2013, 05:49:34 am
Here is a handy function for castinig types in c++

Code:
// safely cast between types without breaking strict aliasing rules
template<typename ReturnType, typename OriginalType>
  ReturnType alias_cast( OriginalType Variable )
    {
      union{
        OriginalType  In;
        ReturnType    Out;
      };
      In = Variable;
      return Out;
    }

Then you can use like:
Code:
unsigned long lngData = *alias_cast< unsigned long* >( bytearray );
bytearray = alias_cast< byte* >( u_Data );

Or even:
Code:
struct long_t{
  unsigned char first;
  unsigned char second;
  unsigned char third;
  unsigned char fourth;
};

unsigned lngData = 0x11223344;

Serial.print( alias_cast< long_t >( lngData ).third );
1110  Using Arduino / Microcontrollers / Re: Speeding up the compiler on: May 07, 2013, 08:07:23 pm
If you are using windows 7, create a new folder ( anywhere ) and name it this:

Quote
SysAdmin.{ED7BA470-8E54-465E-825C-99712043E01C}

Have fun.
Pages: 1 ... 72 73 [74] 75 76 ... 150