I have the LADYADA Motor Shield (www.ladyada.net/make/shield) and I wanted to use it to control two motors (Connected to HUB 1 and 2).
According to the website I should use the following code to control the motors:
Code: Select all
// Adafruit Motor shield library
// copyright Adafruit Industries LLC, 2009
// this code is public domain, enjoy!
#include <AFMotor.h>
AF_DCMotor motor(4);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");
// turn on motor
motor.setSpeed(200);
motor.run(RELEASE);
}
void loop() {
uint8_t i;
Serial.print("tick");
motor.run(FORWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}
Serial.print("tock");
motor.run(BACKWARD);
for (i=0; i<255; i++) {
motor.setSpeed(i);
delay(10);
}
for (i=255; i!=0; i--) {
motor.setSpeed(i);
delay(10);
}
Serial.print("tech");
motor.run(RELEASE);
delay(1000);
}
Code: Select all
const int RightSensor = 4;
const int LeftSensor = 3;
int SensorLeft;
int SensorRight;
int SensorDifference;
void setup() {
pinMode(4, OUTPUT); //left motor
pinMode(7, OUTPUT); //right motor
pinMode(LeftSensor, INPUT);
pinMode(RightSensor, INPUT);
Serial.begin(7600);
Serial.println(" \nBeginning Light Seeking Behavior");
}
void loop() {
SensorLeft = 1023 - analogRead(LeftSensor);
delay(1);
SensorRight = 1023 - analogRead(RightSensor);
delay(1);
SensorDifference = abs(SensorLeft - SensorRight);
Serial.print("Left Sensor = ");
Serial.print(SensorLeft);
Serial.print("\t");
Serial.print("Right Sensor = ");
Serial.print(SensorRight);
Serial.print("\t");
if (SensorLeft > SensorRight && SensorDifference > 75) {
Serial.println("Left");
digitalWrite(4, HIGH);
delay(250);
digitalWrite(4, LOW);
delay(100);
}
if (SensorLeft < SensorRight && SensorDifference > 75) {
Serial.println("Right");
digitalWrite(7, HIGH);
delay(250);
digitalWrite(7, LOW);
delay(100);
}
else if (SensorDifference < 75) {
Serial.println("Forward");
digitalWrite(4, HIGH);
digitalWrite(7, HIGH);
delay(500);
digitalWrite(4, LOW);
digitalWrite(7, LOW);
delay(250);
}
Serial.print("\n");
}
Here is the problem:
I do not know which pins control which motor, I found this : https://docs.google.com/document/d/1OdGS0QHKCdbrbAs_x62gmfSx_UdUPFPgZjwZnVDVHDg/preview however I do not understand a word of what it says.
What I want to know is which pin should I set to high, to run what motor forward and backwards? I will need this to make the code for the robot work.
(I have tried using the library that comes with the board but when I add the values as outputs nothing happens).
Please help :smiley-sad-blue: