Go Down

Topic: A Hovercraft (Read 1 time) previous topic - next topic

luketheduke

Help me with identifying what the problem(s) is in this code for a hovercraft.


Quote

int m2 = A2;
int p1 = 1;
int f1 = A1;
int f3 = A3;
int m1 = A5;
// There are two motors with transistors (tip120) on the + lead as a esc on pins A2 and A5.
// A Piezo on pin D1 for the warning.
//And the fans are two to a transistor on pins A1 and A3.
//Written by: Lukas Severinghaus on 4/18/12.
void setup(){}
void loop(){
goto "start";
goto "Forward";
goto "turn";
goto "forward";
goto "STOP";
}
void "start"(){
  HIGH = p1;
  delay(2500);
  LOW = p1;
  analogWrite(f1, 255);
  analogWrite(f2, 255);
}
  void "Forward"(){
    analogWrite(m1, 255);
    analogWrite(m2, 255);
    delay(2000);
    analogWrite(m1, 0);
    analogWrite(m2, 0);
  }
  void "turn"(){
    analogWrite(m2, 200);
    delay(2500);
    analogWrite(m2, 0);
  }
  
  
  void "STOP"(){
    HIGH = p1;
    delay(5000);
    LOW = p1;
    analogWrite(f1, 0);
    analogWrite(f2, 0);
  }


a.d

Perhaps you should tell us what exactly is not working with it, rather than leaving us to guess?

dxw00d

#2
Apr 19, 2012, 08:44 pm Last Edit: Apr 19, 2012, 08:50 pm by dxw00d Reason: 1
There is so much wrong there, I have to ask. Have you looked at any of the example sketches? Or any of the tutorial pages? Or any other C programs?

Code: [Select]
goto "start";
goto "Forward";
goto "turn";
goto "forward";
goto "STOP";

You can't goto a character literal. Even if you could, you wouldn't goto a function anyway, you would just call it.

Code: [Select]
void "start"(){
Function names are not character literals.

Code: [Select]
 HIGH = p1;
You can't assign a variable to a constant.

Look at the examples in the IDE. Google for C tutorial and learn some basics.

Grumpy_Mike

Quote
Help me with identifying what the problem(s) is in this code for a hovercraft.

The major problem is that the code is not written in C. I don't know what language it is written in but it is defiantly not C and as such will not run on the arduino.

You also have not defined any pins as outputs so you can never control anything.

robtillaart


my interpretation of your code to something that compiles, don't have a clue if it does what you want but it might help you
Code: [Select]


int m2 = A2;
int p1 = 1;
int f1 = A1;
int f2 = A3;
int m1 = A5;

void setup()
{
  start();
  forward();
  turn();
  forward();
  stop();
}

void loop()
{

}

void start()
{
  digitalWrite(p1, HIGH);
  delay(2500);
  digitalWrite(p1, LOW);
  analogWrite(f1, 255);
  analogWrite(f2, 255);
}

void forward()
{
  analogWrite(m1, 255);
  analogWrite(m2, 255);
  delay(2000);
  analogWrite(m1, 0);
  analogWrite(m2, 0);
}

void turn()
{
  analogWrite(m2, 200);
  delay(2500);
  analogWrite(m2, 0);
}


void stop()
{
  digitalWrite(p1, HIGH);
  delay(2500);
  digitalWrite(p1, LOW);
  analogWrite(f1, 0);
  analogWrite(f2, 0);
}


Looking at the quality of your code I advice you to spend a day or 5 on the tutorial section of Arduino to get familiar how to code it. It seems like a lot of time but it will be worth it as you will learn all the fundamentals how to program the A.

And if you serious want to control a hovercraft you should learn to code without delay() function as it blocks your system from new commands.

Succes.
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up