PWM programming on Arduino Nano


hello
pretty new in area won't start learning different way program stepper motor. first project make camera move same speed earth moving, long time exposure. tried couple of month ago, have plan use microsteps instead of fullsteps. far manage drive motor forty steps instead of four. motor 200 steps per revolution , 1 revolution on camera takes 46 rev on gear. want stepper smooth possible, if possible control that? code far, realize complicated! glad if can me easier way of making camera take great night pictures...: use arduino nano.


#include <stepper.h>
int motorpin1 = 3;
int motorpin2 = 5;
int motorpin3 = 6;
int motorpin4 = 9;
int = 255;
int b = 254;
int c = 250;
int d = 243;
int e = 234;
int f = 221;
int g = 204;
int h = 182;
int = 153;
int j = 111;
int k = 0;

#define runevery(t) (static typeof(t) _lasttime;(typeof(t))((typeof(t))millis() - _lasttime) > (t);_lasttime += (t))
 


unsigned long previousmillis;
unsigned long steps;
byte motor1step = 0;
int stepinterval;


void setup() {
  pinmode(motorpin1, output);
  pinmode(motorpin2, output);
  pinmode(motorpin3, output);
  pinmode(motorpin4, output);

 
}
void loop(){
 
 {
    stepinterval = 234;
      steps = 0;  // reset steps
  }

  // clockwise stepper code
  if (millis() >= previousmillis){
    previousmillis = previousmillis+stepinterval;
    motor1step = motor1step +1;
 
    if(motor1step == 5){
      motor1step = 1;
      steps = steps +1;
    }
  }
  switch (motor1step){
case 1:
 analogwrite(motorpin1, a); //1
analogwrite(motorpin2, k);
analogwrite(motorpin3, k);
analogwrite(motorpin4, k);
 break;
  case 2:
 analogwrite(motorpin1, b); //2
 analogwrite(motorpin2, j);
 analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 3:

 analogwrite(motorpin1, c); //3
 analogwrite(motorpin2 , i);
  analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 4:

 analogwrite(motorpin1, d); //4
 analogwrite(motorpin2, h);
 analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 5:

 analogwrite(motorpin1, e); //5
 analogwrite(motorpin2, g);
 analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 6:
 analogwrite(motorpin1, f); //6
analogwrite(motorpin2, f);
 analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 7:

 analogwrite(motorpin1, g); //7
 analogwrite(motorpin2, e);
 analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 8:

 analogwrite(motorpin1, h); //8
 analogwrite(motorpin2, d);
 analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 9:

 analogwrite(motorpin1, i); //9
 analogwrite(motorpin2, c);
analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);

 break;
  case 10:
 analogwrite(motorpin1, j); //10
analogwrite(motorpin2, b);
 analogwrite(motorpin3, k);
 analogwrite(motorpin4, k);
 break;
  case 11:
  analogwrite(motorpin1, k); //11
  analogwrite(motorpin2, a);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, k);
 break;
  case 12:

  analogwrite(motorpin1, k); //12
  analogwrite(motorpin2, b);
  analogwrite(motorpin3, j);
  analogwrite(motorpin4, k);

 break;
  case 13:
  analogwrite(motorpin1, k); //13
  analogwrite(motorpin2, c);
  analogwrite(motorpin3, i);
  analogwrite(motorpin4, k);
 break;
  case 14:

  analogwrite(motorpin1, k); //14
  analogwrite(motorpin2, d);
  analogwrite(motorpin3, h);
  analogwrite(motorpin4, k);
 break;
  case 15:

  analogwrite(motorpin1, k); //15
  analogwrite(motorpin2, e);
  analogwrite(motorpin3, g);
  analogwrite(motorpin4, k);
 break;
  case 16:

  analogwrite(motorpin1, k); //16
  analogwrite(motorpin2, f);
  analogwrite(motorpin3, f);
  analogwrite(motorpin4, k);
   break;
  case 17:
 
  analogwrite(motorpin1, k); //17
  analogwrite(motorpin2, g);
  analogwrite(motorpin3, e);
  analogwrite(motorpin4, k);
 break;
  case 18:

  analogwrite(motorpin1, k); //18
  analogwrite(motorpin2, h);
  analogwrite(motorpin3, d);
  analogwrite(motorpin4, k);
 break;
  case 19:

  analogwrite(motorpin1, k); //19
  analogwrite(motorpin2, i);
  analogwrite(motorpin3, c);
  analogwrite(motorpin4, k);
 break;
  case 20:

  analogwrite(motorpin1, k); //20
  analogwrite(motorpin2, j);
  analogwrite(motorpin3, b);
  analogwrite(motorpin4, k);
 break;
  case 21:

  analogwrite(motorpin1, k); //21
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, a);
  analogwrite(motorpin4, k);
 break;
  case 22:

  analogwrite(motorpin1, k); //22
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, b);
  analogwrite(motorpin4, j);
 break;
  case 23:

  analogwrite(motorpin1, k); //23
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, c);
  analogwrite(motorpin4, i);
 break;
  case 24:

  analogwrite(motorpin1, k); //24
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, d);
  analogwrite(motorpin4, h);
 break;
  case 25:

  analogwrite(motorpin1, k); //25
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, e);
  analogwrite(motorpin4, g);
 break;
  case 26:

  analogwrite(motorpin1, k); //26
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, f);
  analogwrite(motorpin4, f);

 break;
  case 27:
  analogwrite(motorpin1, k); //27
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, g);
  analogwrite(motorpin4, e);
 break;
  case 28:

  analogwrite(motorpin1, k); //28
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, h);
  analogwrite(motorpin4, d);
 break;
  case 29:

  analogwrite(motorpin1, k); //29
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, i);
  analogwrite(motorpin4, c);
 break;
  case 30:

  analogwrite(motorpin1, k); //30
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, j);
  analogwrite(motorpin4, b);
 break;
  case 31:

  analogwrite(motorpin1, k); //31
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, a);
 break;
  case 32:

  analogwrite(motorpin1, j); //32
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, b);
 break;
  case 33:

  analogwrite(motorpin1, i); //33
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, c);
 break;
  case 34:

  analogwrite(motorpin1, h); //34
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, d);
 break;
  case 35:

  analogwrite(motorpin1, g); //35
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, e);
 break;
  case 36:

  analogwrite(motorpin1, f); //36
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, f);
 break;
  case 37:

  analogwrite(motorpin1, e); //37
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, g);
 break;
  case 38:

  analogwrite(motorpin1, d); //38
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, h);
 break;
  case 39:

  analogwrite(motorpin1, c); //39
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, i);
 break;
  case 40:

  analogwrite(motorpin1, b); //40
  analogwrite(motorpin2, k);
  analogwrite(motorpin3, k);
  analogwrite(motorpin4, j);
 break;
 

  }}



what have connected arduino? using pwm drive stepper motors highly unusual. arduino can't provide near enough current power stepper motor.


Arduino Forum > Using Arduino > Programming Questions > PWM programming on Arduino Nano


arduino

Comments

Popular posts from this blog

invalid use of void expresion in FlexiTimer2 library

error: a function-definition is not allowed here before '{' token

LED Strip Code