Show Posts
Pages: 1 ... 2249 2250 [2251] 2252 2253 ... 3347
33751  Using Arduino / Programming Questions / Re: Inconsistency using strdup() on: November 30, 2011, 12:13:55 pm
Quote
The empty brackets are there to show that the object exists.  It is then defined properly in the constructor (of which there may be many different constructors in the future).
Wrong. Wrong. Wrong.

You can not, in the constructor, change the size of an array that is a member of a class.

Even if you could, where do you try?
Code:
Input::Input(){
  pBreaker_ = breaker_;
  pEquals_ = equals_;
  pnCommands_ = &nCommands_;
}

Get rid of the useless breaker_ and equals_ arrays. In the default constructor:
Code:
pBreaker = strdup(";");
pEquals = strdup("=");

(Lose those annoying _ on the end of every name, too.)

In other constructors, you can have something like this:
Code:
Input::Input(char *sepSetOne)
{
  pBreaker = sepSetOne;
  pEquals = strdup("=");
}

Input::Input(char *sepSetOne, char *sepSetTwo)
{
  pBreaker = sepSetOne;
  pEquals = sepSetTwo;
}
33752  Using Arduino / Programming Questions / Re: Inconsistency using strdup() on: November 30, 2011, 12:00:32 pm
Code:
  char   breaker_[];
  char* pBreaker_;
  char   equals_[];
  char* pEquals_;
Empty brackets for arrays result in arrays that are 0 sized. Worthless, in other words.

Code:
  pBreaker_ = breaker_;
  pEquals_ = equals_;
Pointing to garbage is not useful. Are you planning on allowing dynamic definition of the delimiters?
33753  Using Arduino / Programming Questions / Re: C++ code converting to Arduino on: November 30, 2011, 11:54:25 am
Quote
Please check my code and share your knowledge.
You go first. Share your knowledge of what the problem is.
33754  Using Arduino / Programming Questions / Re: Loop question on: November 30, 2011, 11:35:57 am
Have you not been introduced to the use of Serial.begin(), Serial.print(), Serial.println() and the Serial Monitor for debugging? It is not necessary to do everything blind.
33755  Using Arduino / Programming Questions / Re: Inconsistency using strdup() on: November 30, 2011, 11:32:29 am
We need to see the header file for the class, too. It looks to me like you are using pointers unnecessarily, in some cases.

Code:
  pnCommands_ = &nCommands_;
Why do you need a pointer to nCommands_?

Code:
  parseString(cData_,pBreaker_,aCommands_,pnCommands_);
  parseCommands(aCommands_,pEquals_,aCommands2_,pnCommands_);
There is no checking that aCommands_, etc. are actually allocated.

All the debug output is useless, unless you show what was being parsed.

Finally, the two step parsing is unnecessary. You can parse the whole string in one pass.

Find an equal sign. Copy the token. Find a semicolon. If you got a token, store the pointer to the copied token, and copy the second token. Repeat until you get a NULL.
33756  Using Arduino / Programming Questions / Re: Inputting and comparing characters on: November 30, 2011, 11:06:07 am
Quote
Lets say i have a touch screen which i have allocated 4 touch buttons to.
OK. All together now "I have a ..."

Quote
The buttons are labled 1,2,3 and 4.
The Arduino doesn't know that.

Quote
My question is how do i get the arduino to recognise each button as a character "1,2,3,4".
How is the Arduino now knowing which button is pressed?

If you get the Arduino to recognize that the "button labled 3" is pressed, it is no big deal to assign a char of any value to an array.
Code:
char array[4];
byte index = 0;

char pretendChar = '0';
if(/* Somehow detect "button labled 3" is pressed */)
{
   pretendChar = '3';
}
// else other button checks

array[index] = pretendChar;
33757  Using Arduino / Programming Questions / Re: Help with a Voltage Indication System on: November 30, 2011, 10:15:49 am
Code:
  if (sensorValue = 0) {
This assigns the value 0 to sensorValue. If you are going to do this, why are you bothering to read from the sensor. (== is more likely what you want).
33758  Using Arduino / Programming Questions / Re: Interrupt Problems - Accelerometer on: November 30, 2011, 10:13:46 am
Quote
The register for the DATA_READY interrupt is 0x80 or as I've read 1<<7 can be used
Maybe you need new batteries in your calculator. 1 << 7 is not 0x80. It is 0x40.

The smiley faces would not happen if you posted code correctly, using the # button.

Quote
but this has been difficult, I've been at it all day!
You'll be at it even longer if you don't tell us what the problem is.
33759  Using Arduino / Programming Questions / Re: Array related class problem on: November 30, 2011, 10:07:56 am
Code:
  private :
    int list[];
It's hard to believe that this even compiles. You are not specifying a size for this array.

Code:
intArray::intArray(int l){
  list[l];
  len = l;
}
What do you think that the list[l] statement is doing? It is not setting the size of the array.

33760  Using Arduino / Programming Questions / Re: Loop question on: November 30, 2011, 09:58:55 am
Quote
so that code should work right?
You already said that it did work...
33761  Using Arduino / Programming Questions / Re: Generating fonts (glyphs) for LED matrices and POV on: November 30, 2011, 09:20:59 am
Quote
How does Arduino code save 16bit numbers?
As an int.

Quote
Is it better if I make my code produce pairs of bytes rather than a 16bit number?
That would make using it much harder, in my opinion.
33762  Using Arduino / Programming Questions / Re: Loop question on: November 30, 2011, 09:19:21 am
Quote
when I upload the sketch it shows 1 on the LED right away and when I pass my hand in the front of the sensor it changes to 0. Shouldn't that be other way around?
The sensor reads HIGH (as in HIGH light level) when it gets plenty of light, and LOW (man, it's dark in here) when it doesn't get any light. So, the behavior seems reasonable.

You can, of course, change the behavior, by displaying 1 when LOW and 0 when HIGH.
33763  Using Arduino / Programming Questions / Re: Regarding Switch Case on: November 30, 2011, 09:15:30 am
Quote
can we   switch(port) ? whats the syntax? (like switch(PA) or switch(PortA) etc ) we are using Atmega 168.
Yes, you can. What port (which pins) are you wanting to switch on?
33764  Using Arduino / Networking, Protocols, and Devices / Re: Problem with Skynet SKM53 GPS module on: November 30, 2011, 09:13:59 am
The data sheet suggests a 10k resistor between the GPS's RX and TX pins and the Arduino's RX and TX pins.

You do have VCC and GND of the GPS connected to the appropriate pins on the Arduino, right?

33765  Using Arduino / Networking, Protocols, and Devices / Re: Problem with Skynet SKM53 GPS module on: November 30, 2011, 08:43:35 am
Quote
I tried disconnecting the RX pin of the arduino from anything,   and the stream of zeros stopped.
Well, of course they did. You removed the source.

Quote
Under what circumstances,  could a serial input to an arduino generate a stream of zero bytes  when in fact there might be nothing talking to it at all ?
None that I know of. There are resistors on the serial pins that prevent noise from being considered valid input.

If I were posting on a forum asking for help, I would not be citing parts of the data sheet for a device. I'd post a link to the device and the data sheet for the device. Your mileage may vary.
Pages: 1 ... 2249 2250 [2251] 2252 2253 ... 3347