Show Posts
Pages: 1 [2] 3 4 ... 32
16  Using Arduino / Programming Questions / Re: function pointer & memory selection on: April 11, 2014, 06:52:44 am
Perhaps you could pass in a pointer to a union and, upon return from the function, extract the value you need that the function placed in the union.
17  Using Arduino / Programming Questions / Re: How do i find an average value from an array? on: April 11, 2014, 06:46:01 am
If you know you need the average, why wouldn't you maintain a running average as the values are read in from the sensors? You could still save them in the array, but why read them a second time?
18  Using Arduino / Programming Questions / Re: How to use switch case for light dependent resistor sensor's value on: April 10, 2014, 09:29:24 pm
@PaulS: You're going soft on us:

Quote
You can't read from the pin in the 6th position of a 4 element array.

I would have expected something more entertaining,  like:

Quote
You can read the 6th position of a 4 element array, it's just that it probably won't be anything useful.
19  Using Arduino / Programming Questions / Re: Problem with array scope and array content on: April 10, 2014, 09:20:57 pm
strcat() works with strings and char arrays are not necessarily strings. Some compilers do the equivalent of a memset() with zero that would make the array appear to work on the first pass. However, strcat() assumes there is a null-terminated sequence of data to which it adds the new data. Since the first time strcat() is called, all zeros looks like all nulls and things work out great. On the second iteration of the loop, that may not be the case. I'm not sure because I don't know how the compiler allocates memory for local arrays on each pass through a loop. I'm just saying it might be a problem. Brad's suggestion of using strcpy() on the first call is a good one.
20  Using Arduino / Programming Questions / Re: Reversing a Sketch with a button on: April 10, 2014, 11:56:36 am
How does buttonState get changed? Try looking at what comes back from the switch. Also, why an analogRead() when you're just looking for a switch closure?
21  Using Arduino / Programming Questions / Re: Problem with RTC and time library on: April 09, 2014, 12:00:21 pm
It makes it easier for us if you post your code. With the cursor in the Arduino IDE, do Ctrl-T to format it in a standard way, then use the sharp sign ('#') and copy your code between the two code tags.
22  Using Arduino / Programming Questions / Re: Help with extracting coordinates for usage in GPS program on: April 08, 2014, 09:04:39 pm
Try looking at: strchr(), strnchr(), and strtok(). Read the descriptions, think about what you're trying to do and write it down, then go back and read the descriptions again. I think you'll know exactly what to do.
23  Using Arduino / Programming Questions / Re: Time on a display on: April 08, 2014, 01:31:42 pm
Don't the values returned have to be converted from BCD back to decimal??
24  Using Arduino / Programming Questions / Re: How to determing 'Caps Lock' status on: April 08, 2014, 08:57:31 am
@PaulS: eBay is selling a book titled "Diet for Fat FIngers" as an eBook...
25  Using Arduino / Programming Questions / Re: function pointer & memory selection on: April 08, 2014, 08:52:56 am
void pointers pose certain problems and are usually used to get around the compiler complaining about a missing type specifier for a pointer. If you want to write a "generic" function that returns a pointer, you can do something like this:

Code:
void setup() {
 //Initialize serial and wait for port to open:
  Serial.begin(115200);

}

void *myGeneric() {
   // Do something
}

void loop() {
  int *ptr;
  long *lPtr;
 
  ptr = (int *) myGeneric();
  lPtr = (long *) myGeneric();

}

The casts on the return value is required so that the scalar associated with the data type of the pointer is known.
26  Using Arduino / Programming Questions / Re: Running out of Ram ? on: April 08, 2014, 08:41:33 am
You might sprinkle calls to freeMemory() at different point in loop() to see if that's your problem. Check out:

http://playground.arduino.cc/Code/AvailableMemory

27  Using Arduino / Programming Questions / Re: function pointer & memory selection on: April 08, 2014, 07:03:49 am
I'm not sure exactly what the code is trying to do, but I changed the line:

Code:
        pMemory = &memory_System.bSlidingSwitch_Left;

to

Code:
       
       pMemory = (word *) &memory_System.bSlidingSwitch_Left;

and the code compiles. The error is caused because, without the cast, there is a type mismatch between the two data types. Many compilers don't complain on a "silent cast", because you're attempting to place a smaller data type (boolean) into a larger data type (word). That is, you're pouring one byte of information into a two-byte bucket. Any reasonably good compiler will complain on assignment in the other direction (pour two bytes of information into a one-byte bucket, since that runs the risk of losing information).
28  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 07, 2014, 11:44:14 pm
My guess is that we are talking to cross purposes. If an array name is used as the argument in a function call, you're saying its a pointer to the first element. I agree because that is also the definition of the lvalue of the array. That is, array and &array[0] are the same thing. Once I know that, I can use the array in the function body since I know where it is stored in memory.  You can see that using the following code fragment:

Code:
  int array[10];
  Serial.print("array = ");
  Serial.print((int)array);
  Serial.print("   &array[0] = ");
  Serial.println((int)&array[0]);

That's all I was trying to say: Given the proper type specifier for an array passed to the function, you get the memory address of the array (lvalue), which equates to the name of the array,  which allows you to reference the array in the function.
29  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 07, 2014, 09:42:43 pm
I was referring to the statement that ...it is not a reference to the array or a pointer to it..  We were talking about array names being passed to a function.
30  Using Arduino / Programming Questions / Re: Array Basics (sizeof) on: April 07, 2014, 09:19:21 pm
I disagree. You state:

...it is not a reference to the array or a pointer to it. Passing the array name without subscript operators decays the array type to a pointer of its first element, nothing to do with the original array.

Even your own quote says it's a pointer. If it has nothing to do with the original array, then why is the type of the pointer required as part of the parameter being passed?  The reason is because pointer operations are scaled to the data type being pointed to. Further, if it has nothing to do with the array, then why is the value passed the lvalue of the array? Indeed, it has everything to do with the array, otherwise the function wouldn't have a memory address to allow any operation to be performed on it. Indeed, if I pass in an array name and pass additional parameters for its length and rank, I can reference the array in a way that matches its original definition.

Pages: 1 [2] 3 4 ... 32