Show Posts
Pages: 1 ... 3 4 [5] 6 7 ... 15
61  Forum 2005-2010 (read only) / Syntax & Programs / Re: Pseudo Code Clarification on: August 25, 2010, 11:38:42 pm
[edit]This post is intended as a "searching" or "roving" functionality.  It is what I used as a basis to create a "Sumo Robot".  I see that you have already worked out you "static" functionality

Also, an LDR can make a cheap alternative to find a different surface under your robot[/edit]

If you detect a front left line sensor, you should stop, back up, turn right, and then continue forward.

Just turning right might lead to your left wheel going off the table (think about when the angle is close to 90deg with the end of the table).  Also, if you don't back up, you may end up with your sensor going past the white line, robot thinks it's fine and keeps going forward (fail).
62  Forum 2005-2010 (read only) / Syntax & Programs / Re: 8-byte double to 32-bit float on: August 17, 2010, 07:21:56 am
Hey there Si,

If you are hungry for literature, you would love these.

This is where I have learnt the bulk of everything, and the author was on the standardisation committee which came up with the C and C++ standards:

http://www.amazon.com/C-Complete-Reference-4th-Ed/dp/0072121246/ref=sr_1_9?ie=UTF8&s=books&qid=1282047413&sr=8-9
http://www.amazon.com/C-Complete-Reference-Herbert-Schildt/dp/0072226803/ref=sr_1_3?ie=UTF8&s=books&qid=1282047413&sr=8-3

These cover the entire c and c++ languages with lots of sample code.
63  Forum 2005-2010 (read only) / Syntax & Programs / Re: systems of equations solving on: August 26, 2010, 12:21:11 am
Hey there,

This is a problem that many academics have tried to address in the past.  There is heaps out there on how to do this, so if I where you, I'd read up on how a few different people have tried to do this and try a few of them yourself.

Here is a good start:
http://en.wikipedia.org/wiki/Multilateration

smiley

Look for "geometric locating process".
64  Forum 2005-2010 (read only) / Syntax & Programs / Re: Multiple code selection on: August 23, 2010, 10:22:25 pm
If we are to teach NickLee1983 to "fish", I believe that it is best to start at pseudo code.

This is where you write out what you want your program to do step by step.  When you do this, try to avoid loops (except for the main one with the Arduino).  This helps fault finding later on.

When I post pseudo, I always start it with (pseudo) and end it with (/pseudo), so that everyone knows where it starts and finishes.


To get you started, I believe that this is the way to go:

(pseudo)

Start

If button is being pushed
    wait 40mSec

    if button is still being pushed
    set flag high
    wait for button to be released
[/list]
if flag is high
    increment button counter
    if counter is more than the maximum value (4)
    reset counter
clear flag[/list]

if counter is 1
    (what would be in loop1...)

if counter is 2
    (what would be in loop2...)

if counter is 3
    (what would be in loop3...)

if counter is 4
    (what would be in loop4...)
Back to start

(/pseudo)


This goes through and updates the counter every "loop" (from "start" to "back to start".

The parts "(what would be in loopx...)" only get run if the counter is on the right number.

Notice that I do not take what the button is saying on face value (to avoid Impulse noise and bouncing)

The "flag" is just a Boolean variable.



Does this make sense?


Teach a man to pseudo, and he can code for life.  Don't teach him pseudo, and he can't catch fish... or something like that...

smiley
65  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help with alternating LEDs on: August 23, 2010, 09:37:04 pm
I don't think that your code looks all that wrong (that I can see).

Does it work when you use the serial window on the Arduino program?
66  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help needed with keypad and LCD display on: August 17, 2010, 02:41:35 am
Have a look into millis()

http://www.arduino.cc/en/Reference/Millis

What you want to do is check to see if 10000 milliseconds has elapsed.

<--! untested -->
Code:
int waitForKey()
{
   int key = NO_KEY;
   unsigned long _start_time = millis();

   while(((key = keypad.getKey()) == NO_KEY) && ((millis()-_start_time) < L10000))
   {
      // Do nothing
   }
   return key;
}


(or something like that...)
67  Forum 2005-2010 (read only) / Syntax & Programs / Re: Help needed with keypad and LCD display on: August 16, 2010, 01:23:48 am
What you need to do is to make sure that 10000 mS has not passed in the 'while' logical condition

ie.
(pseudo)

store start time

while(button is not pushed AND current time - start time is less then 10s)
    Do nothing
If there was no key pressed return no key

If there was a key pressed return a key

(/pseudo)

I'm sure that you would have no trouble with this.
68  Forum 2005-2010 (read only) / Syntax & Programs / Re: Compass Heading Compiler Error on: August 23, 2010, 09:24:57 pm
also, did you want "h" to be a float?
69  Forum 2005-2010 (read only) / Syntax & Programs / Re: Compass Heading Compiler Error on: August 23, 2010, 09:23:18 pm
change:
char[] getDirection(unsigned long h){
to...
char *getDirection(unsigned long h){
70  Forum 2005-2010 (read only) / Syntax & Programs / Re: PROGMEM vs #define vs const on: August 19, 2010, 05:41:16 am
With strings, use PROGMEM.

(For the reasons given by PaulS)

When doing things like only including error checking, or having set numbers that you need to change easily (like pin numbers), define would be more appropriate.
71  Forum 2005-2010 (read only) / Syntax & Programs / Re: Need Help Programing Sharp GP2D120 on: August 20, 2010, 07:26:24 am
Hey there,

This example should help you smiley

http://arduino.cc/en/Tutorial/AnalogInput
72  Forum 2005-2010 (read only) / Syntax & Programs / Re: Serial commands - A tiny bit of help needed! on: August 19, 2010, 06:03:06 am
I hope that you weren't actually sending the word "command" before the number.

It may pay to put this before the "myStepper.step(value);" code:

Code:
Serial.println(value, DEC); //see what the value of "value" is
for( ; ; );                          //loop forever (stop program here).

See if the value of "value" is what you expect.

Using Serial.print for debugging is very useful.

The "for( ; ; );" statement isn't really necessary, but I usually put it in just in case is sends something too stupid to the hardware I'm using.

Do lots of (serial) tests on different things, and tell us what you get.

smiley
73  Forum 2005-2010 (read only) / Syntax & Programs / Re: Serial commands - A tiny bit of help needed! on: August 17, 2010, 09:17:59 am
Global means that you declare the variable outside the loop or setup section.

I think that it would be better as a static variable.

this means that you declare it as:
static boolean negative = false;

74  Forum 2005-2010 (read only) / Syntax & Programs / Re: Creating a Library - Few Questions on: August 17, 2010, 03:19:41 am
I'll be honest, I have only made .cpp libraries whilst using the arduino, and .c libraries using an AVR.

You can use .c libraries on the Arduino though, as the SD card library is in .c format.  But as for creating them, I don't know...


75  Forum 2005-2010 (read only) / Syntax & Programs / Re: Creating a Library - Few Questions on: August 16, 2010, 09:47:12 pm
The way to do it is to put all your function definitions in the .h file

void function1(void);
int funtion2(void);

... ect

and put the function in a .c file
function1() {

/* Do something */

}

...
Pages: 1 ... 3 4 [5] 6 7 ... 15