Pages: [1]   Go Down
Author Topic: Pot motors held issue  (Read 262 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 240
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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);
 
}


* image.jpg (1068.3 KB, 2592x1936 - viewed 23 times.)
Logged

UK
Offline Offline
Shannon Member
****
Karma: 222
Posts: 12534
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

UK
Offline Offline
Faraday Member
**
Karma: 101
Posts: 6211
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

...R
Logged

London
Offline Offline
Edison Member
*
Karma: 46
Posts: 1368
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
#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:
motor.setSpeed(mappedPotVal);
Logged

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

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...
Logged

Pages: [1]   Go Up
Jump to: