Code for bi-directional motor


i new electronics , using arduino uno infineon motor control shield btn8982ta control bi-directional motor side mirror on vehicle. need incorporate 2 momentary switch buttons (one changes direction, , 1 on/off). have developed code use project. however, code not seem working. far, have included button changes directions. trying work before add other button in. looking suggestions improve code program works. attached information regarding motor control shield pin definitions , functions. thank you.





#define is_1 a0
#define is_2 a1
#define in_1 3
#define in_2 11
#define inh_1 12
#define inh_2 13


#define tconst 100       // delay time between steps

const int buttonpin = 7;     // number of pushbutton pin
int motor_dc = 0;    // actual dc
int motor_dc_max = 60;   // 50% duty cycle

int = 0;
int buttonstate = 0;         // variable reading pushbutton status




void  setup () {
  pinmode(buttonpin, input);
  pinmode (in_1, output );
  pinmode (in_2, output );
  pinmode (inh_1, output );
  pinmode (inh_2, output );
 
 // reset_ports ();
 
  digitalwrite (inh_1,1);
  digitalwrite (inh_2,1);
}

void fade_motor ( int port)

  {
  motor_dc =  map (60, 0, 100, 0, 255);
  analogwrite (port, motor_dc);

  delay (tconst);
 
  }

 
void reset_ports ()
{
  digitalwrite (in_1,0);
  digitalwrite (in_2,0);
}
 
void  loop () {

 buttonstate = digitalread(buttonpin);


  if (buttonstate == high) { //if momentary push button pushed , held, motor move forward. if push button let go, motor move backward.
  fade_motor (in_1);
 } else {
  fade_motor (in_2);
 }

  reset_ports ();
}   

does happen?  e.g. motor move
try putting print statements in code can trace execution flow

also use code tags


Arduino Forum > Using Arduino > Programming Questions > Code for bi-directional motor


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino DUE ADC to DAC Piezo 30 Khz-100Khz

Indesign and MathType fonts