Motors and Servos

HI,

so I’m new at this to start off. trying to control my 12V DC Motor (50RPM /6amps) through a MD10C driver.
I have the code listed bellow, but im having issues so far. (1) once everything is plunged in, the motor is running. (2) none of the two bottoms are working (to turn CCW ad CW).

#define LEFT 1   // pin 1 is connected to left button
#define RIGHT  0  // pin 0 is connected to right button
//define pin name
#define PWM 2
#define DIR 3
// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);          //  setup serial
pinMode(LEFT,INPUT_PULLUP); // assign pin 1 ass input for Left button
pinMode(RIGHT,INPUT_PULLUP);// assing pin 0 as input for right button
pinMode(PWM,OUTPUT);
pinMode(DIR,OUTPUT);


}

void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(LEFT);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (LEFT == HIGH) {
  // turn Motor CW on:
  digitalWrite(PWM, HIGH);
  digitalWrite(DIR, LOW);
} else {
  digitalWrite(PWM, LOW);}
// read the state of the pushbutton value:
buttonState = digitalRead(RIGHT);
// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (RIGHT == HIGH) {
  // turn Motor CCW on:
  digitalWrite(PWM, HIGH);
  digitalWrite(DIR, HIGH);
} else {
  digitalWrite(PWM, LOW);}  
}
 if (LEFT == HIGH) {

Oopsif (RIGHT == HIGH) {Ditto

sorry bud, what do you by that?.. is the code wrong?

LEFT and RIGHT are constants.

You used these constants correctly to read the states of two switches, then ignored the states in the comparisons.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.