6.07.2015

arduino code

This is a simple arduino code for rotating the plate. From easy driver sample code, I extract step and dir part to start rotating. Also, I use steps and usDelay parts from mapamok. However, I had to play with delay part and mostly usDelay part to sink properly with rotating plate with speed 4.


int x;
float rotation = 0.0;

void setup()
{
  pinMode(6,OUTPUT); // Enable
  pinMode(5,OUTPUT); // Step
  pinMode(4,OUTPUT); // Dir
  digitalWrite(6,LOW); // Set Enable low
  //Serial.begin(9600);
}

void loop()
{
  float deg = 0.51;
  int steps = abs(deg)*(1.0/0.225);
  float usDelay = (1.0/4.0)*125;
//113
//150 movie fast
//100 rol fast
//120 movie little fast
//110 roll fast

digitalWrite(4,HIGH); // Set Dir high

for(x = 0; x < steps; x++)
{
  digitalWrite(5,HIGH);
  delayMicroseconds(usDelay);
  digitalWrite(5,LOW);
  delayMicroseconds(usDelay);
}
  delay(7);
}