Go Down

Topic: Motors and Servos  (Read 8116 times) previous topic - next topic

prolapseg0d

Mar 17, 2020, 12:09 am Last Edit: Mar 18, 2020, 01:52 am by prolapseg0d
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).

Code: [Select]

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

TheMemberFormerlyKnownAsAWOL

#1
Mar 17, 2020, 09:50 pm Last Edit: Mar 17, 2020, 09:50 pm by TheMemberFormerlyKnownAsAWOL
Code: [Select]
if (LEFT == HIGH) {
Oops
Code: [Select]
if (RIGHT == HIGH) {Ditto
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

prolapseg0d

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

TheMemberFormerlyKnownAsAWOL

LEFT and RIGHT are constants.

You used these constants correctly to read the states of two switches, then ignored the states in the comparisons.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

Go Up