Go Down

Topic: Question about my Sketch. (Read 1 time) previous topic - next topic

johncc

OmegaRA,

Have you been able to get your motor to even turn on, using the code I posted in reply #11 or UKHeliBobs in #20?

This would confirm whether your shield is working and your wiring is valid...

John

OmegaRa


OmegaRA,

Have you been able to get your motor to even turn on, using the code I posted in reply #11 or UKHeliBobs in #20?

This would confirm whether your shield is working and your wiring is valid...

John


I was at work all day and didn't get to tinker. Just got home and finished dinner and a grocery shop will attempt the tinker now. Have to go downstairs and load your sketch to the UNO and hook it up to see.

OmegaRa


The fact remains that neither sketch uses 3 pins defined as outputs to control the shield...

...You need to start with simple sketches that run the motor(s) and work from there
Try this
Code: [Select]
int motorA_dir = 12;    //direction
int motorA_brake = 9;   //brake
int motorA_speed = 3;   //speed

void setup()
{
  pinMode (motorA_dir, OUTPUT);    //set 3 pins to be outputs
  pinMode (motorA_brake, OUTPUT);
  pinMode (motorA_speed, OUTPUT);

  digitalWrite(motorA_dir,HIGH);  //direction 1
  digitalWrite(motorA_brake,LOW);  //brake off

  for (int motorSpeed = 0;motorSpeed <=255 ;motorSpeed++)
  {
    analogWrite(motorA_speed, motorSpeed);  //set the motor speed
    delay(100);                             //slow down the for loop a little
  }
  analogWrite(motorA_speed, 0);  //let the motor coast to a stop
}

void loop()
{
}

One motor should run up from its slowest speed to its highest then stop.  Note how giving the Arduino pins names helps to make the code more readable.


I see what you are saying. I will give that a go as well, so obviously the sketch you provided is for a single motor, but once I get at least one working then it is a matter of adding the second..

OmegaRa


OmegaRA,

Have you been able to get your motor to even turn on, using the code I posted in reply #11 or UKHeliBobs in #20?

This would confirm whether your shield is working and your wiring is valid...

John


okay, yes, your sketch gets the one motor spinning :)

johncc

That's great-- your shield and wiring is working!

Code: [Select]
void leftMotor( int direction, int speed)
{
    digitalWrite( LEFT_MOTOR, direction); //Establishes direction fwd/back
    digitalWrite( LEFT_BRAKE , LOW);      //Disengage the Brake
    digitalWrite( LEFT_SPINNER, speed);   //Spins the motor
}


Can you see how you would add a rightMotor() ?

Cheers,
John

Go Up