Show Posts
Pages: 1 ... 33 34 [35] 36 37 ... 268
511  Using Arduino / Programming Questions / Re: Maze Following Robot Logic on: April 22, 2014, 01:45:35 am
I didn't get far into reading your program before I became confused as to which distance related to which direction, left, right or front so I am afraid that I stopped trying to understand the details at that point. 

Can I suggest that you rename your distance variables to reflect the direction that they relate to in order to make the logic clearer.  It would also help to have the motors named as left and right rather than A and B and for their directions to be named forward and reverse rather than CW and CCW.

Also, whilst it is nothing to do with the logic of the program, I noticed that you have 3 separate functions to read distances when it could be done with a single function to which you passed a parameter indicating the sensor to be read.  You are also passing max and min ranges to the function when there is no need as they are global variables.
512  General Category / General Discussion / Re: Good practices (Arduino Programming) on: April 21, 2014, 03:14:21 pm
How can you get any debugging done when you are constantly peering at code to ascertain what code is in what block ?

If you are short of vertical screen space because of the stupid aspect ratios that are being forced on us then turn your monitor 90 degrees, work in portrait mode and take command of your editor, particularly if it allows code collapsing.
513  Using Arduino / Programming Questions / Re: Problem understanding non blocking delay via millis() on: April 21, 2014, 01:46:26 pm
No need to complicate things.
The LED is on otherwise the timing period would not have started.  The period ends.  What should happen ?
514  General Category / General Discussion / Re: Good practices (Arduino Programming) on: April 21, 2014, 01:43:43 pm
I will start the ball rolling.

Every { and } goes on its own line with no other code.
Code to be executed when an if is true always has { and } around it, even if it is only one line of code.
Give variables appropriate names to indicate their purpose.
Use defines or variables to give pin numbers meaningful names.
Consider putting blocks of code in appropriately named functions to make it easier to test and debug.
Use Auto Format often.  Not only does it tidy up the code it points out missing/extra brackets and braces.
Test small sections of code or functions as you go along using appropriate test data, hard coded into variables if necessary.
515  Using Arduino / Programming Questions / Re: Problem understanding non blocking delay via millis() on: April 21, 2014, 01:32:59 pm
Code:
      if(currentMillis - previousMillis > interval)
Something should happen if this is true....
516  Using Arduino / Programming Questions / Re: How to display inputed words by Serial on LCD on: April 21, 2014, 12:19:27 pm
Agreed wholeheartedly.
517  Using Arduino / Programming Questions / Re: How to display inputed words by Serial on LCD on: April 21, 2014, 11:46:14 am
Quote
So, the name should be char_count.
That could still be confusing as the variable is used to set the LCD column to be printed in.
518  Using Arduino / Project Guidance / Re: How to use an infrared sensor? on: April 21, 2014, 11:44:06 am
Quote
But I do not know how to program!
See my reply to your other post in French

Quote
Then you will need to learn.  Have you tried any of the examples in the IDE ?
519  Using Arduino / Project Guidance / Re: comment utiliser un capteur infrarouge ? on: April 21, 2014, 11:42:22 am
Quote
Mais je ne sais pas comment programmer !!!
Then you will need to learn.  Have you tried any of the examples in the IDE ?

Ensuite, vous aurez besoin d'apprendre. Avez-vous essayƩ l'un des exemples dans l'IDE?
520  Using Arduino / Programming Questions / Re: Looking for reference info on #if, #else, #ifdef, #endif, etc on: April 21, 2014, 11:19:16 am
Quote
Is there another reference area that I am missing?
Google, perhaps ?  The terms are not Arduino specific but relate to C and C++

http://www.cplusplus.com/doc/tutorial/preprocessor/
521  Using Arduino / Programming Questions / Re: Problems with reading quadrature encoder using code from playground on: April 21, 2014, 11:03:40 am
Interrupts are automatically disabled when in an ISR
Serial.println() uses an interrupt
You have Serial.println() in your ISR

Variables that change in an ISR should be declared volatile
You change a variable in your ISR that is not declared volatile

Fix both problems and see whether things improve.
522  Using Arduino / Programming Questions / Re: Slow down analogRead or Serial.print without delay() on: April 21, 2014, 10:04:32 am
Do you mean slow it down or print less frequently ?
Either way, to avoid using delay() embrace the principle in the BlinkWithoutDelay example in the IDE.

Save a start time then check periodically whether the required time has elapsed.  If it has then act accordingly.  If not, go away and do something else such as reading sensors or input, then check the elapsed time again and so on.

Keith's method will work but the BWD method will give you precise control of the timing.
523  Using Arduino / Programming Questions / Re: if else or switch case? on: April 21, 2014, 01:48:47 am
still not sure if switch case is better or not than if/else but just starting with the crazy compare statements how does this look? seem like itll work?

Code:
if((btbuffer[3] == 'C') && (btbuffer[4] == 'H') && (btbuffer[5] == '6') ){//original method example
            analogWrite(ch6, numberinput);
            EEPROM.write(60,numberinput);
    } else
    if(! strcmp(commandstring, "ch5")){ // new attempt simple example
           analogWrite(ch5, numberinput);
          EEPROM.write(50,numberinput);
    } else
//my command string is 5 char long(for now) with the null terminator so will comparing to  a shorter string work?

 if(! strcmp(commandstring, "RED")){ //comparing to three character string
//change outputs for red
} else
if(! strcmp(commandstring,"GREEN")){//comapring to full length string
//change outputs for green
}
As you have not posted your full code or a smaller but complete example it is difficult to give a definitive answer but here are some comments.

Either fill the char array with NULLS before inserting the individual characters into it, or after inserting each character insert a NULL after it.

It does not matter, within reason, how long the input string and string constant used for comparison are but the input string must start at position zero in the array if you are going to use strcmp() to compare the strings.  You could use strstr() to find one string within another if necessary.

It seems that the input string is coming from human input which is notoriously unreliable.  Anything that you can do to filter out rubbish input or to convert it to a common form, such as using the toupper() function before adding the character to the string will be advantageous.

Overall it looks like you are on the right lines.
524  Using Arduino / Programming Questions / Re: if else or switch case? on: April 20, 2014, 05:00:11 pm
If you add a null terminator to your array of chars you will turn it into a string.  toupper() and strcmp() definitely work with strings.  I have never used Strings but I assume that there are equivalent functions.
525  Using Arduino / Programming Questions / Re: How can I stop for loop by a comand on: April 20, 2014, 04:40:33 pm
Quote
Ok I need for loop to run part of the code constantly..
Isn't that what the loop() function does for you ?

Quote
I using for loop for constant update or read the info from serials I will have 2 difren serials with incoming data on them. So I need run them on the same sketch.
You do not need 2 different for loops, or even one for loop, to read from 2 different serial inputs.
Pages: 1 ... 33 34 [35] 36 37 ... 268