Poll
Question: My code is not working for me
write new code - 7 (70%)
just drop the project - 3 (30%)
Total Voters: 10

Pages: [1]   Go Down
Author Topic: A Hovercraft  (Read 1527 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Jr. Member
**
Karma: 0
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
  }

Logged

Leeds, UK
Offline Offline
Full Member
***
Karma: 0
Posts: 134
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 21
Posts: 3113
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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:
void "start"(){
Function names are not character literals.

Code:
 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.
« Last Edit: April 19, 2012, 01:50:56 pm by dxw00d » Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34528
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 221
Posts: 13848
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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:

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.
Logged

Rob Tillaart

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

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 34528
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
int p1 = 1;
This implies you are trying to use pin 1 as an output. This is used by the serial communications along with pin 0. Pick another pin.
Logged

Toronto, Canada
Offline Offline
Edison Member
*
Karma: 2
Posts: 1234
"Keep it R.E.I.L. - "Research, Experiment, Investigate and Learn"
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The analog pins A2,A1,A3, A5 are for analogRead() only. To use analogWrite(), use Digital pin 3,5,6,9,10,11. Look at your UNO closely, and see the ~ <-- the tiny wave character. That indicate the PWM pins for an analogWrite().

I look at the original program, it look like a BASIC program... Arduino use C++ variant. Don't think BASIC when coding the Arduino, Think C++.

What are you trying to do ? The motors are control by a relay ? A transistor using a PWM wave to control the motors ?

I agree with Grumpy_Mike here about pin 1. For me, I never use pin 0, 1 and 13. Specialy digital pin 0 and pin 1. To me, they call "Someone using the bathroom / toilet" pins  smiley-mr-green  So you don't use the bathroom / toilet when someone is inside. 
« Last Edit: April 28, 2012, 10:57:32 am by Techone » Logged

Pages: [1]   Go Up
Jump to: