Pages: [1]   Go Down
Author Topic: Why orange  (Read 478 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

When i write a function to turn a motor to go forward ie

void forward (int dist, int vel)                    // Forward function, dist is time in milliseconds, vel is speed
{
 
  digitalWrite(led,HIGH);
  digitalWrite(motor1pin, LOW);                     // Set H bridge pins to move both motors in the same direction
  digitalWrite(motor2pin, HIGH);
  digitalWrite(motor3pin, LOW);
  digitalWrite(motor4pin, HIGH);
  analogWrite (motor1speed, vel);                   // Turn on motor 1 by supplying a value 0-255 to En (pin 1)
  analogWrite (motor2speed, vel);                   // Turn on motor 2 by supplying a value 0-255 50 En (pin 9)
  delay (dist);                                     // keep both motors going for dist milliseconds
}
the forward command always appears in orange.

I have a similar setup to reverse the motor(s), that also becomes orange txt.

Now ive written code to spin 180 degrees. But the code looks ok but the spin function never turns orange, and doesnt work when I call it?

What is happenning?
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 86
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What version of the IDE are you using? Can you post the code that is not working?

Is the word "forward" turning orange? I believe functions turn orange in the IDE, but the parameters passed to them stay black.
« Last Edit: April 25, 2012, 04:30:23 am by boredat20 » Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Assuming you mean the word 'forward' appears in orange text in the IDE, it would be because 'forward' is listed in one of the keywords.txt files. I presume spin isn't. If you want help to fix the problem, read http://arduino.cc/forum/index.php/topic,97455.0.html then post your sketch.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 552
Posts: 46266
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the forward command always appears in orange.
Color coding is based on the keywords.txt files delivered with each library.

Quote
Now ive written code to spin 180 degrees. But the code looks ok but the spin function never turns orange, and doesnt work when I call it?
Is that a question or a statement? If it is a statement, then what was the question? If it is a question, where is the spin() function code, and where do you call it?

What kind of motor are you talking about? I get the impression that the motor is a continuous rotation servo. If that is the case, you can't make it spin just 180 degrees.

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Ive got the code working now. But i still dont understand why some functions are coloured orange like forward and reverse, whereas spin stays black.
int motor1pin = 3 ;                                //  H bridge pin 2
int motor2pin = 4 ;                                //  H bridge pin 7
int motor3pin = 6 ;                                //  H bridge pin 10
int motor4pin = 7 ;                                //  H bridge pin 15


int motor1speed = 9 ;                              //  To En pin 1: Use PWM to alter speed of motor 1
int motor2speed = 2 ;                             //  To En pin 9: Use PWM to alter speed of motor 2
int led = 13;
int dist;
int vel;


void setup ()

{
 
  pinMode (motor1speed, OUTPUT);                   // Define pins as outputs
  pinMode (motor2speed, OUTPUT);
  pinMode (motor1pin, OUTPUT );
  pinMode (motor2pin, OUTPUT );
  pinMode (motor3pin, OUTPUT );
  pinMode (motor4pin, OUTPUT );
  pinMode (led,OUTPUT);
}

void stop ()

{
  digitalWrite (motor1speed, LOW);                  // Make pin 1 (En) low to stop motor 1
  digitalWrite (motor2speed, LOW);                  // Make pin 9 (En) low to stop motor 2
 
}

void forward (int dist, int vel)                    // Forward function, dist is time in milliseconds, vel is speed
{
 
  digitalWrite(led,HIGH);                           // just for debugging
  digitalWrite(motor1pin, LOW);                     // Set H bridge pins to move both motors in the same direction
  digitalWrite(motor2pin, HIGH);
  digitalWrite(motor3pin, LOW);
  digitalWrite(motor4pin, HIGH);
  analogWrite (motor1speed, vel);                   // Turn on motor 1 by supplying a value 0-255 to En (pin 1)
  analogWrite (motor2speed, vel);                   // Turn on motor 2 by supplying a value 0-255 50 En (pin 9)
  delay (dist);                                     // keep both motors going for dist milliseconds
}
void reverse (int dist, int vel)                    // Reverse function, just reverse HIGH and LOW commands
{
  digitalWrite(led,LOW);                            // just for debugging
  digitalWrite(motor1pin, HIGH);
  digitalWrite(motor2pin, LOW);
  digitalWrite(motor3pin, HIGH);
  digitalWrite(motor4pin, LOW);
  analogWrite (motor1speed, vel);
  analogWrite (motor2speed, vel);
  delay (dist);
}
void spin  (int dist, int vel)
{
  digitalWrite(motor1pin, HIGH);
  digitalWrite(motor2pin, LOW);
  digitalWrite(motor3pin, LOW);
  digitalWrite(motor4pin, HIGH);
  analogWrite (motor1speed, vel);
  analogWrite (motor2speed, vel);
  delay (dist);
}
 

void loop()

{
 
 forward (5000,170);                               // forward for 5 seconds at about half speed

 stop ();                                          // stop both motors
 
 delay (2000);                                     // wait 2 seconds
 
 reverse (5000,170);                               // reverse
 
 stop();
 
 delay(2000);
 
 spin (1000,200);                                   // spin alter parameters to go 180 degrees
 
 stop ();
 
 delay (2000);

}
Logged

Gosport, UK
Offline Offline
Faraday Member
**
Karma: 19
Posts: 3114
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So you missed the bit about [code]...[/code] tags in point 6 of http://arduino.cc/forum/index.php/topic,97455.0.html

There are a number of files called keywords.txt that are supplied with some libraries (Arduino supplied and third-party). If a word (not a function) appears in one that the IDE can see, then it gets coloured.
« Last Edit: April 25, 2012, 04:54:46 am by dxw00d » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks and sorry about the tags. I havent loaded any libraries, do some get automatically included ?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 552
Posts: 46266
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I havent loaded any libraries, do some get automatically included ?
Yes, a whole slew of them.
Logged

Pages: [1]   Go Up
Jump to: