// newtc.co.kr    newtc@newtc.co.kr
// Arduino Digital pin 9,  8, 7,  6
//  AM-CS2P        pin A, /A, B, /B    conntect to (D0, D2, D1, D3)  or (D4, D6, D5, D7) 
//                                     and Power VCC, GND and 
//                                         Motor power (+12V, GND)
//                                    After that, control varaible resistor in the AM-CS2P module when moving, 
//                                    it will make the motion smoothly with that torque.

#include <Stepper.h>

const int stepsPerRevolution = 200; // For steps per one time rotation
Stepper myStepper(stepsPerRevolution, 9, 8, 7, 6);
                                      
void setup() {
  // initialize digital pin 13 as an output.
  myStepper.setSpeed(60); // one time rotation per second.   60 time rotation per minute
  Serial.begin(9600); 
  
  // prints title with ending line break 
  Serial.println("Testing AM-CS2P with U-Style(Arduino at heart)");
}

// the loop function runs over and over again forever
void loop() {
  // 200 step : 1 time rotation  
  //if stepsPerRevolution is plus, then it rotates in Clockwise
  //if stepsPerRevolution is minus, then it rotates in Counter Clockwise
  
  while(1){
      myStepper.step(stepsPerRevolution);
      delay(500);                          // wait for 0.5 second
      myStepper.step(-stepsPerRevolution);
      delay(500);                          // wait for 0.5 second      
      
      Serial.print("."); 
      // Motor_CLK_L pulse
  }  
}
