Help with Arduino code
#25
Chuck,

Try this code as a test.

Code:
/*

Test that turns the stepper motor in one direction for about 3 seconds and then reverses it for 3 seconds in a continuous cycle. Digital pin 12 is the step signal and 13 is the direction signal.

*/

#include <Wire.h>

//setup vars
const int stp = 12;  //connect pin 12 to step
const int dir = 13;  // connect pin 13 to dir
const int StepsPerRotation = 200; //Set Steps per rotation of stepper
const int TableRatio = 90; //ratio of rotary table
const int Multiplier = (StepsPerRotation * TableRatio)/360;
const int stepdelay = 1;
float Degrees = 0;                //Degrees from Serial input
float ToMove = 0;                 //Steps to move
int Direction = 1;
int repeat = 0;


void setup()
 {

   pinMode(stp, OUTPUT);
   pinMode(dir, OUTPUT);
 
 }
 

void rotation(float tm, int d)
 {  
   if(d == 0)
     {
       digitalWrite(dir, LOW);
     }
 else
   {
     digitalWrite(dir, HIGH);
   }
 
 for(int i = 0; i < tm; i++)  
  {    
   digitalWrite(stp, HIGH);  
   delay(stepdelay);              
   digitalWrite(stp, LOW);  
   delay(stepdelay);
  }
}


void loop()
{
   if(repeat == 0)
   {
     Degrees = 30;
   }
   
   Degrees = Degrees * Direction;

   if(Degrees < 0)
   {
     ToMove = (Degrees*Multiplier)*-1;
     rotation(ToMove,0);
   }
   else
   {
     ToMove = Degrees*Multiplier;
     rotation(ToMove,1);
   }
   
  if (Direction == 1)
    Direction = -1;
  else
    Direction = 1;
     
}

All it does is to turn the stepper motor in one direction for about 3 seconds and then reverses the direction for about 3 seconds and repeats the cycle until power is removed. Digital pin 12 is the step and 13 is the direction.

Ed
Reply
Thanks given by:


Messages In This Thread
Help with Arduino code - by chucketn - 04-04-2015, 02:33 PM
RE: Help with Arduino code - by Vinny - 04-04-2015, 02:52 PM
RE: Help with Arduino code - by EdK - 04-04-2015, 05:21 PM
RE: Help with Arduino code - by chucketn - 04-04-2015, 06:19 PM
RE: Help with Arduino code - by EdK - 04-04-2015, 06:49 PM
RE: Help with Arduino code - by Vinny - 04-04-2015, 07:05 PM
RE: Help with Arduino code - by chucketn - 04-05-2015, 06:34 AM
RE: Help with Arduino code - by arvidj - 04-05-2015, 08:43 AM
RE: Help with Arduino code - by chucketn - 04-05-2015, 09:40 AM
RE: Help with Arduino code - by EdK - 04-05-2015, 09:57 AM
RE: Help with Arduino code - by EdK - 04-05-2015, 10:38 AM
RE: Help with Arduino code - by chucketn - 04-05-2015, 10:09 AM
RE: Help with Arduino code - by EdK - 04-05-2015, 10:19 AM
RE: Help with Arduino code - by chucketn - 04-05-2015, 12:20 PM
RE: Help with Arduino code - by EdK - 04-05-2015, 02:50 PM
RE: Help with Arduino code - by Vinny - 04-05-2015, 04:25 PM
RE: Help with Arduino code - by chucketn - 04-05-2015, 06:22 PM
RE: Help with Arduino code - by EdK - 04-05-2015, 06:49 PM
RE: Help with Arduino code - by Vinny - 04-05-2015, 06:50 PM
RE: Help with Arduino code - by EdK - 04-06-2015, 08:29 AM
RE: Help with Arduino code - by chucketn - 04-06-2015, 11:25 AM
RE: Help with Arduino code - by EdK - 04-06-2015, 11:48 AM
RE: Help with Arduino code - by Vinny - 04-06-2015, 03:47 PM
RE: Help with Arduino code - by EdK - 04-06-2015, 05:26 PM
RE: Help with Arduino code - by EdK - 04-06-2015, 05:34 PM
RE: Help with Arduino code - by Vinny - 04-06-2015, 05:41 PM
RE: Help with Arduino code - by EdK - 04-06-2015, 05:44 PM
RE: Help with Arduino code - by chucketn - 04-06-2015, 05:58 PM
RE: Help with Arduino code - by chucketn - 04-06-2015, 06:00 PM
RE: Help with Arduino code - by chucketn - 04-06-2015, 06:07 PM
RE: Help with Arduino code - by Vinny - 04-06-2015, 07:48 PM
RE: Help with Arduino code - by EdK - 04-07-2015, 05:41 AM
RE: Help with Arduino code - by chucketn - 04-07-2015, 08:02 AM
RE: Help with Arduino code - by chucketn - 04-07-2015, 08:06 AM



Users browsing this thread: 1 Guest(s)