Show Posts
Pages: 1 ... 52 53 [54] 55 56 ... 122
796  Using Arduino / Programming Questions / Re: two dimensional array problem on: March 07, 2013, 07:45:37 pm
Your initialisation list is wrong:

Code:
int DH[2][3]={{0,90,0,0},
             {12,0,0,0},
             {6,0,0,0}};

Should be only 2 * 3 values = 6 values, you have twelve. Maybe:

Code:
int DH[2][3]={{0,90,0},
             {12,0,0}
};

or:

Code:
int DH[3][4]={{0,90,0,0},
             {12,0,0,0},
             {6,0,0,0}};
797  Using Arduino / Installation & Troubleshooting / Re: Windows 8 on: March 07, 2013, 01:15:13 pm
Have a look on google, there should be lots of info for installing non digitally signed drivers. ( a windows setting has to be disabled )
Once installed, if the IDE is not working, try running the IDE in compatibility mode for an earlier windows ( if windows 8 includes this option ).
798  Using Arduino / Programming Questions / Re: Using pointers to strip values out of an UDP array returned by time server on: March 07, 2013, 10:53:51 am
If this is the line you are concerned about:
Code:
ntpEpoch_POINTER = NTP_POINTER + 40;

The error is due to the types being incompatible, strict aliasing rules are broken if you attempt to dereference a punned type:
Code:
ntpEpoch_POINTER = ( unsigned long* ) ( NTP_POINTER + 40 );

It may work for now, but is not good practice.

Also ensure your endianess is correct:
Code:
unsigned int i = 0x1234;
Serial.print( *( byte* )&i, HEX ); // = 0x34

799  Using Arduino / Storage / Re: HDD Read? on: March 07, 2013, 09:32:46 am
I remember seeing some projects done for ide drives, here is the first one that popped up: http://arduino.cc/forum/index.php?topic=70086.0

The due board has a USB host, so If you could get the USBMassStorage class running, then flash drives and external HDD's are an option. There is some code available ( arduino due USB was/still is based on a library that has many USB classes.
800  Using Arduino / Programming Questions / Re: Some *possibly* useful String functions. on: March 07, 2013, 08:33:16 am
I will work with ur code to get a good understanding of how it works.
So far just reading it, i dont see any loop.

Sorry for the late reply, my account was banned for a few days.

Code:
String StringTrimRight(String InputString, int CharCount) {
  const int Steps = InputString.length() - CharCount;
  if( Steps < 1 ) return( "" ); //Check for invalid or complete trim
  InputString[ Steps - 1 ] = '\0';
  return( &InputString[ 0 ] );
}

The function returns a string object, which is constructed using the pointer provided by "return( &InputString[ 0 ] );", which is the internal char array where String stores its data. The constructor will loop the char array till it hits a null, i.e. "InputString[ Steps - 1 ] = '\0';"
801  Using Arduino / Programming Questions / Re: Delays and unsigned long on: March 01, 2013, 08:27:52 am
volume is promoted to int, and the result overflows 16-bits

100 * 9250 = 11100001110101001000

shortened to 16 bits is 0001110101001000
which is 7496

802  Using Arduino / Project Guidance / Re: PROGMEM Efficiency/wastage/overhead on: March 01, 2013, 07:55:46 am
Also if you are storing it in progmem, there is no need for the 12/13 entry number bits,
you can take the size of the entry and use that to traverse a block of data from the start pgm address.

Code:
//Read first byte of entry.
pgm_read_byte( startAddress + ( sizeof( entry ) * index ) );
803  Using Arduino / Programming Questions / Re: how to call a class from my own library, inside another own library. Help on: March 01, 2013, 07:16:10 am
Cpu.cpp does not include Cpu.h, this may cause problems.

Code:
CpuOutput outputObject;

It should be in the cpp or declared extern, if you want it in the header, the compiler may also need CpuOutput.h to be included in the header.

Code:
CpuOutput outputObject();

This is incorrect as it is a function prototype, taking no parameters and returning a CpuOutput object.

804  Using Arduino / Programming Questions / Re: Some *possibly* useful String functions. on: March 01, 2013, 06:38:53 am
Ensure you have the string library fix ( for function free(), search for it in the forum ) as you may have memory leaks after calling those methods multiple times.

You could reduce the number of temporary objects and reserve more memory to speed things along though.

From your example:
Code:
String StringTrimRight(String InputString, int CharCount) {
    String OutputString;
    String StringBuffer = InputString;
    for (int CharIndex = 0; CharIndex < (StringBuffer.length() - CharCount); CharIndex++) {
        OutputString += StringBuffer.charAt(CharIndex);
    }
    return OutputString;
}
The line 'OutputString += StringBuffer.charAt(CharIndex);' will generate many temporary variables, each one with an allocation.


It can be slightly tweaked:

Code:
String StringTrimRight(String InputString, int CharCount) {
  const int Steps = InputString.length() - CharCount;
  if( Steps < 1 ) return( "" ); //Check for invalid or complete trim
  InputString[ Steps - 1 ] = '\0';
  return( &InputString[ 0 ] );
}

This leaves the String constructor on exit to do all the looping. And only 1 temporary String object.
And as you do not pass InputString by reference, you can modify its contents without harm.

Passing String objects by reference will boost performance, however you have to copy the data to a buffer if the reference cannot change.

This construct below can help you design code that can use variable sized temporary arrays. So no large global working buffer, or oversized local buffer.
Code:
void foo( const int len ){
  char temp[ len ];
}
805  Using Arduino / Displays / Re: how to use bitmap? on: March 01, 2013, 03:05:23 am
Yes, it is the far easier option, to use the SD card would be far more complex. What ever library you are using most probably has a tutorial/example of bit map use.
806  Using Arduino / Programming Questions / Re: PROGMEM question on: March 01, 2013, 02:21:30 am
It all depends on the scenario its used in. For your example:

The compiler for arduino is set to optimisations favouring small code, so in this case it might not be compiled away due to it having to unroll the loop. If the loop was unrolled, then yes it could be a compile time constant, depending on its use elsewhere.

All of this depends on weather the variable is marked external, used by non-constant reference to any of the data, or something looks at the address of the array, and sometimes the compiler cannot guarantee a variable is a 'compile time constant', even when you clearly program it as one.

If you are going to expect/want the compiler to unroll the loop, then just do it in code yourself. Templates will help you achieve unrolling of complex loops ( not for the loop above ). And if you do unroll, you can then use an enum to organise the data, instead of an array, then you can guarantee the values are compile time constants.

Then you will also have to weigh the result of having unrolled code ( can get large ), vs an array in progmem used in a loop.
807  Community / Exhibition / Gallery / Re: Twitter Feed Machine on: February 28, 2013, 09:40:20 am
Nice one, maybe you could use a secret twitter account to add/remove new feeds by having it read instructions in the tweet.
808  Using Arduino / Displays / Re: how to use bitmap? on: February 26, 2013, 10:41:45 am
If you wish to use a .c file it will have to be compiled into the sketch.
You could store a binary file of the data, then using the SD library, read it into your sketch first then pass it to the drawBitmap function.

For now, include the .c file in your sketch and try that way.
809  Using Arduino / Programming Questions / Re: ERROR on: February 25, 2013, 07:13:29 pm
String.toCharArray(num, 11);

That is wrong, stop using it, delete it.

'd' has only read one character, which 'following number' do you expect to store in num.

You are looping as long as there is data:

Code:
Serial1.available() > 0

But you do not do anything with it unless it is 'a'

and there is no end '}' on your loop.
810  Using Arduino / Programming Questions / Re: ERROR on: February 25, 2013, 06:42:14 pm
Did you see the posts in your last thread: http://arduino.cc/forum/index.php/topic,150807.0.html

Quote
if the start of the data is d

there is only 1 character, and yes it is d but you check weather it is 'a'

String.toCharArray(num, 11);

String is not a variable, this line is not valid.
Pages: 1 ... 52 53 [54] 55 56 ... 122