Show Posts
Pages: [1] 2 3 ... 53
1  Using Arduino / Programming Questions / Re: Looking for general code to read from Serial port and return char* on: September 14, 2014, 12:54:12 am
Show the code that's calling this and how it's being used.

I think you may have a scope issue.  You create a local array called xbeeOut and fill it with data, then you return a pointer to it.  Immediately after the function returns the pointer, the local array is destroyed, so now the pointer points at memory you no longer own.  If you make the array global or static then it would still exist and the pointer would be valid after it is returned.
2  Using Arduino / Programming Questions / Re: Arduino not incrementing correctly on: September 10, 2014, 06:05:39 pm

I could use Grumpy_Mike's idea, but I am not really sure how to do it, you guys expect a certain level of arduino experience that I don't have yet lol

Grumpy_Mike's idea isn't a programming thing.  It's a math thing.  

If I am dealing with distance, and I have distances between 0.00001 and 0.00100 meters then I have to deal with decimals right?  Wrong.  If I multiply every number by 100000 I can deal with distances instead in micrometers.  I would have 10 to 1000 micrometers and now I can use a integer type variable.  

Well you can do that with any kind of number, not just metric units.  If I want 9 digits behind the decimal point I use a long int and multiply everything by 1 * 10^9.  When I use that number I have to remember that I multiplied it.  I'm more likely to change my interpretation of the number (thinking in terms of units) instead of ever converting anything to a float.  I'd lose precision going to a floating point variable, they only get 7 digits of precision.

You have to think of precision not as numbers behind the decimal, but as the total number of digits involved.  You can scale those numbers however you need to.  
3  Using Arduino / Programming Questions / Re: Simple question but I thought it would be easier to ask... on: September 10, 2014, 05:57:11 pm
I'm guessing at what you have here since you haven't shown the whole code, but I think I get the point.  

No, the names that you give to functions and variables are all gone once the compiler is done.  So you can't build them at run time out of variables.  That's a common trap new programmers fall into.  It can be done with function pointers in an array, but that's overly complicated.  

Instead, make an array that holds one byte for each number 0-9 with the bits set for how to set the display and then create one function that takes an integer as an argument and uses that integer to index said array.  Take the bits that you get and set your digits.  Now one function does all the numbers and you can do what you want to do.  Look in the reference section under the bitmath stuff.  
4  Using Arduino / Programming Questions / Re: Mysterious "ghost definition" of a user-defined function on: September 08, 2014, 02:52:40 pm
Plus,
Quote
Serial.write(output);
Is not the same as Output, hopefully just a typo.

And the compiler doesn't know what "CloseDome;" is.

Also, I wasn't aware this worked:
Quote
if (IsDead && DomeOpen) // Somehow IsDead works even though it is not written as IsDead()
  {
    DomeClosed = CloseDome; // Close the dome. Should put a check in this function to verify success.
    DomeOpen = false; // This should only be set to false if the closeDome procedure was successful.
  }


Sure it works.  isDead is a pointer to the function isDead().  Since that pointer actually points to something it returns true every time.  He might as well have written:

Code:
if (true && DomeOpen){
5  Using Arduino / General Electronics / Re: Rotary Encoder on: August 29, 2014, 10:12:32 pm
Code:
Serial.println(encoderPos[0]);
Serial.println(encoderPos[1]);
6  Using Arduino / Programming Questions / Re: How would I include 10 functions into an array? on: August 29, 2014, 10:11:14 pm
The end result is being able to cycle through the 10 functions one by one with a button press but I needed the functions to be simplified down into something I could increment(++) through.

What about a simple solution like this pseudo code

Code:
// pressing a button increments the variable  funcSelect

switch (funcSelect) {
    case 1:
        function1();
        break;
    case 2:
       function2();
         break;
}

...R

I don't know what you're doing here, it doesn't make sense to me. Sorry.



Google "C++ switch case"

7  Using Arduino / General Electronics / Re: Rotary Encoder on: August 29, 2014, 02:49:21 pm
Throw some Serial.print lines in the main loop and print out encoderPos and see if it is changing at all.
8  Using Arduino / Project Guidance / Re: my first project on: August 29, 2014, 02:28:00 pm
It might be a good idea to describe what you want to do.  Then I can assure you that someone here is going to ask what have you tried.  What parts of the reference did you not understand?  Have you tried any of the examples?  This site is nothing but people helping newbies get started.  So yeah, someone will help you I'm sure, but you have to say what you want help with.
9  Using Arduino / Programming Questions / Re: Trouble with function calling on: August 29, 2014, 02:24:04 pm
Code:
   void loop() {
  // put your main code here, to run repeatedly:
Serial.println("FirstState");
zzz=APFtt(3,4,1,1.4,3);
Serial.println(zzz);
Serial.println("SecondState");

}




float APFtt (float xc,float yc,float sf,float sl,float sr) {
  qx=xc;
  qy=yc;

Name must be the same.
You have APFtt and float APFtt



No, he did that part right.  WHen you declare the function you have to list the return type.  That's the float part.  But when you call the function you don't say that part.  You just use the function name.

The problem is likely related to the array index out of bounds mentioned above.
10  Using Arduino / General Electronics / Re: Rotary Encoder on: August 29, 2014, 01:57:36 pm
Make a short sketch that just increments a counter in the ISR and hook it up to a simple pushbutton.
11  Using Arduino / General Electronics / Re: Rotary Encoder on: August 29, 2014, 01:04:28 pm
Yes, and encoderPos and Rotating and any anything that could potentially be modified inside that ISR.
12  Using Arduino / Programming Questions / Re: How would I include 10 functions into an array? on: August 28, 2014, 05:21:04 pm
Google "C++ pointers" and you'll learn way more than anyone could ever explain here.

After that google "C++ pointer to function" for your specific application.
13  Using Arduino / General Electronics / Re: Rotary Encoder on: August 28, 2014, 05:18:51 pm
You need to make all the variables that get changed in an interrupt volatile. 

eg.

Code:
volatile boolean a_set = false;
14  Using Arduino / General Electronics / Re: Rotary Encoder on: August 28, 2014, 03:51:51 pm
Oh, it's a Teensy 2.0.   I guess I could go back to the OP. 

Well in that case you need pins 5,6,7,8.  You have it right in the post but in the code you have 0,1,2,3.
15  Using Arduino / General Electronics / Re: Rotary Encoder on: August 28, 2014, 03:48:13 pm
Or is this a leonardo?
Pages: [1] 2 3 ... 53