Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Start up delay on: April 26, 2012, 11:23:07 am
 How do I get a delay at the start of the loop? that only happens once. ie I power up the arduino. It waits five seconds before running through loop(). But the five second delay doesnt happen each time it goes through the loop?

Code:
loop()
{
delay(5000);
}

Gives a five second delay every time the loop is executed, i just want to have it delay just once, at the beginning.
2  Using Arduino / Programming Questions / Re: Why orange on: April 25, 2012, 07:11:24 am
Thanks and sorry about the tags. I havent loaded any libraries, do some get automatically included ?
3  Using Arduino / Programming Questions / Re: Why orange on: April 25, 2012, 04:47:00 am
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);

}
4  Using Arduino / Programming Questions / Why orange on: April 25, 2012, 04:24:20 am
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?
Pages: [1]