Hi, I am new at programming with Arduino. I have been trying to make the faders move and stop at the right position. I am trying to use the following approach: I need the potentiometer to move to 555 so I wrote some code that adds and subtracts 5 of the desire number. (550-560) so I need the fader to stop at any point in between that set of numbers. I am trying to make the motor go slower so that the fader has less inertia and is easier to control. I am encountering a problem that says that "too many arguments to function 'void L293D'". Im not sure what to do about this, and id appreciate some advise. I am driving the motor with an H bridge.
#define P1A 6
#define P2A 5
#define EN12 9
void L293D ();
int potmeterPin = A0;
int currentpot = 0;
int potmeterPin2 = A3;
int potmeterVal2 = 0;
int upperset;
int lowerset;
const int motorDown = 5;
const int motorUp = 6;
const int speedStep =15;
const int speedDelay = 1000;
void setup() {
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(P1A, OUTPUT);
pinMode(P2A, OUTPUT);
pinMode(EN12, OUTPUT);
}
void loop() {
currentpot = analogRead(potmeterPin);
Serial.println(currentpot);
potmeterVal2 = analogRead(potmeterPin2);
Serial.println(potmeterVal2);
upperset = potmeterVal2 + 5;
Serial.println(upperset);
lowerset = potmeterVal2 - 5;
Serial.println(lowerset);
if ( currentpot > lowerset) {
if (currentpot == lowerset){
L293D('R',90, 0);// stop motor
delay(2000);
}
else (currentpot >= lowerset) {
L293D('R',90, 0);// stop motor
delay(2000);
}
}
Function Code
void L293D(char dir,int spd, int en)
{
if(dir =='L')
{
if(en ==0){
Serial.println(" CW Motor Stopped");
}else{
Serial.print(" Rotating CW: ");
Serial.println(spd);
}
digitalWrite(EN12 ,en);
analogWrite(P1A,spd);
digitalWrite(P2A,LOW);
}else{
if(en ==0){
Serial.println(" CCW Motor Stopped");
}else{
Serial.print(" Rotating CCW: ");
Serial.println(spd);
}
digitalWrite(EN12 ,en);
digitalWrite(P1A,LOW);
analogWrite(P2A,spd);
}
}
Here is your code with corrections, formatted and posted according to the forum guidelines. You can go back and fix your original post by highlighting the code and clicking the </> in the menu bar after formatting the code with the IDE autoformat function (ctrl-t or Tools, Auto Format).
#define P1A 6
#define P2A 5
#define EN12 9
void L293D ();
int potmeterPin = A0;
int currentpot = 0;
int potmeterPin2 = A3;
int potmeterVal2 = 0;
int upperset;
int lowerset;
const int motorDown = 5;
const int motorUp = 6;
const int speedStep = 15;
const int speedDelay = 1000;
void setup()
{
Serial.begin(9600);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(P1A, OUTPUT);
pinMode(P2A, OUTPUT);
pinMode(EN12, OUTPUT);
}
void loop()
{
currentpot = analogRead(potmeterPin);
Serial.println(currentpot);
potmeterVal2 = analogRead(potmeterPin2);
Serial.println(potmeterVal2);
upperset = potmeterVal2 + 5;
Serial.println(upperset);
lowerset = potmeterVal2 - 5;
Serial.println(lowerset);
if ( currentpot > lowerset)
{
if (currentpot == lowerset)
{
L293D('R', 90, 0); // stop motor
delay(2000);
}
else if (currentpot >= lowerset) // ********* added if
// else can't have an argument
{
L293D('R', 90, 0); // stop motor
delay(2000);
}
}
} // ****************** added }
// Function Code ******************* added //
void L293D(char dir, int spd, int en)
{
if (dir == 'L')
{
if (en == 0)
{
Serial.println(" CW Motor Stopped");
}
else
{
Serial.print(" Rotating CW: ");
Serial.println(spd);
}
digitalWrite(EN12 , en);
analogWrite(P1A, spd);
digitalWrite(P2A, LOW);
}
else
{
if (en == 0)
{
Serial.println(" CCW Motor Stopped");
}
else
{
Serial.print(" Rotating CCW: ");
Serial.println(spd);
}
digitalWrite(EN12 , en);
digitalWrite(P1A, LOW);
analogWrite(P2A, spd);
}
}
Your code was missing a } to close loop(), a comment symbol before " Function Code" and an if with the else with arguments.
Thank you for the help, now I don't get the that error.
I want to be able to move the motor until it reaches at certain point inside the set of numbers described on the post. I have a 2nd potentiometer attached and I want the motorized fader to mimic what that potentiometer is doing to a 5+- or error?, any thoughts on how is the best way to accomplish this? I am using an H gate to control the motor
How does your program know the position of the fader motor? Is there positional feedback to the program from the fader motor?
Please post a schematic diagram of the system. Hand drawn, photographed and posted is fine. Include all pin names/numbers, components, their part numbers and/or values and power supplies.
For the purposes of a system that works, photos and text are sufficient. But for a system that doesn't work, the verification of a real schematic is an absolute necessity. Please provide one.