Go Down

Topic: Pot motors held issue (Read 342 times) previous topic - next topic

Bstanko6

I have a sainsmart(Ada fruit) motor shield l293d, just got it. I went on the arduino playground and installed the library. Tried the example codes and the motor works just fine. I want to hook it up to a pot, and control the motor through the motorshield. Here is the problem, after reading and rereading, cannot find the motorPin designation for motor 1 terminal on the shield. Is their one? I have done this on the UNO, and used 3 as my motorPin. On the shield, I hook it into the terminal... How can I attach to a pin? Or is there a function that replaces a pin with a terminal?

#include <AFMotor.h>

AF_DCMotor motor(1, MOTOR12_64KHZ);

const int potPin = A0;


int potVal = 0;
int mappedPotVal = 0;

void setup()
{
  pinMode(potPin, INPUT);
 
}

void loop()
{
  potVal = analogRead(potPin);
  mappedPotVal = map(potVal, 0, 1023, 0, 255);
 
}

PeterH

I don't understand the question. You have the hardware hooked up and working already and don't seem to be changing the hardware - why is there any issue of terminals versus pins?

You already have an example sketch that controls the motor. You just need to take that example and replace the bit of code that decides what motor speed to use, with your code that reads an analog input and maps that value to a motor speed. Then just connect the ends of your pot to the power and ground pins and the wiper to the analog input, and you're done.
I only provide help via the forum - please do not contact me for private consultancy.

Robin2

I have struggled hard but I can't figure out the connection between your problem and the title of your post???

...R

Henry_Best


I have a sainsmart(Ada fruit) motor shield l293d, just got it. I went on the arduino playground and installed the library. Tried the example codes and the motor works just fine. I want to hook it up to a pot, and control the motor through the motorshield. Here is the problem, after reading and rereading, cannot find the motorPin designation for motor 1 terminal on the shield. Is their one? I have done this on the UNO, and used 3 as my motorPin. On the shield, I hook it into the terminal... How can I attach to a pin? Or is there a function that replaces a pin with a terminal?
Code: [Select]

#include <AFMotor.h>

AF_DCMotor motor(1, MOTOR12_64KHZ);

const int potPin = A0;
int potVal = 0;
int mappedPotVal = 0;

void setup()
{
  pinMode(potPin, INPUT);
}

void loop()
{
  potVal = analogRead(potPin);
  mappedPotVal = map(potVal, 0, 1023, 0, 255);
}

Add in loop()
Code: [Select]
motor.setSpeed(mappedPotVal);

PaulS

Quote
I have struggled hard but I can't figure out the connection between your problem and the title of your post???

I think that the key is too much of the first word went up in smoke first...

Go Up