Show Posts
Pages: 1 ... 72 73 [74] 75 76 ... 142
1096  Using Arduino / Programming Questions / Re: String... need your help.. on: March 07, 2013, 11:39:02 pm
I'm not sure what you are expecting.
The long number is too big for a char, and too big for atoi to turn to an int.

if you want a pointer to the char array, you can use:
Code:
char *c_array = &stringTwo[ 0 ];
1097  Using Arduino / Programming Questions / Re: String... need your help.. on: March 07, 2013, 11:12:12 pm
atoi will do what you want for the byte:

Code:
    Serial.begin( 9600 );
   
    String stringOne = "10 92845401834";
   
    stringOne[2] = '\0';
   
    String stringTobyte = &stringOne[ 0 ];
    String stringTwo = &stringOne[ 3 ];
   
    //Fix up stringOne
    stringOne[2] = ' ';
   
    byte b_Data = atoi( &stringTobyte[ 0 ] );
    Serial.print( "byte: " );
    Serial.println( b_Data );
1098  Using Arduino / Programming Questions / Re: String... need your help.. on: March 07, 2013, 10:52:27 pm
byte = unsigned char, maybe you want uint64_t ( unsigned long long ) as 92845401834 requires 37 bits of storage.

you need to look for the function atoi, fine for the '10' but it wont support 64 bit values ( also, atol is no good ), here is the first topic I found on google:
http://stackoverflow.com/questions/7502926/what-is-atoi-equivalent-for-64bit-integeruint64-t-in-c-that-works-on-both-unix
1099  Using Arduino / Programming Questions / Re: String... need your help.. on: March 07, 2013, 10:26:22 pm
A cheap pointer abuse will work well. Avoid the String library once you are comfortable with arrays and pointers.

Code:
String stringOne = "10 92845401834";

stringOne[2] = '\0';

String stringTobyte = &stringOne[ 0 ];
String stringTwo = &stringOne[ 3 ];

//Fix up stringOne
stringOne[2] = ' ';
1100  Using Arduino / Programming Questions / Re: Can some one please help explaining the output if serial monitor on: March 07, 2013, 08:44:23 pm
It is due to the precision of float.

maybe just recalculate your formulae to just use ints

Code:
int data=5678;
int data1 = data / 100;

Serial.println ( float( data ) / 100.0f );
Serial.println ( data1 );
Serial.println ( data - ( data1 * 100 )  );
 

Output
Quote
56.78
56
78
1101  Using Arduino / Programming Questions / Re: I'd like to add a global.. on: March 07, 2013, 08:02:55 pm
put the variable in the header makred as 'extern', then initialise the object in your sketch, kind of like:

Header:
Code:
extern int a;

Sketch:
Code:
extern int a = 4;

Then the variable is available by any file that includes the header.
Without extern each file that includes it, gets its own copy of the data.
1102  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}};
1103  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 ).
1104  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

1105  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.
1106  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';"
1107  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

1108  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 ) );
1109  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.

1110  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 ];
}
Pages: 1 ... 72 73 [74] 75 76 ... 142