#include <avr/io.h>
#include <util/delay.h>
#include <SoftwareSerial.h>

#define TX PA6
#define RX PA5
SoftwareSerial Serial(RX, TX);

int inA1 = PA0; // input 1 of the stepper
int inA2 = PA1; // input 2 of the stepper
int inB1 = PA3; // input 3 of the stepper
int inB2 = PA4; // input 4 of the stepper

int stepDelay = 25; // Delay between steps in milliseconds


void setup() {
  // put your setup code here, to run once:
   pinMode(inA1, OUTPUT);     
  pinMode(inA2, OUTPUT);     
  pinMode(inB1, OUTPUT);     
  pinMode(inB2, OUTPUT);   
  Serial.begin(9600);
}

void step1() {
  digitalWrite(inA1, LOW);   
  digitalWrite(inA2, HIGH);   
  digitalWrite(inB1, HIGH);   
  digitalWrite(inB2, LOW);   
  delay(stepDelay);
  
}
void step2() {
  digitalWrite(inA1, LOW);   
  digitalWrite(inA2, HIGH);   
  digitalWrite(inB1, LOW);   
  digitalWrite(inB2, HIGH);   
  delay(stepDelay);
}
void step3() {
  digitalWrite(inA1, HIGH);   
  digitalWrite(inA2, LOW);   
  digitalWrite(inB1, LOW);   
  digitalWrite(inB2, HIGH);   
  delay(stepDelay);
}
void step4() {
  digitalWrite(inA1, HIGH);   
  digitalWrite(inA2, LOW);   
  digitalWrite(inB1, HIGH);   
  digitalWrite(inB2, LOW);   
  delay(stepDelay);
}
void stopMotor() {
  digitalWrite(inA1, LOW);   
  digitalWrite(inA2, LOW);   
  digitalWrite(inB1, LOW);   
  digitalWrite(inB2, LOW);   
}


void loop() {
  // put your main code here, to run repeatedly:
if (Serial.available()>0)
{
char incomingbyte=Serial.read();
if (incomingbyte=='c') //clockwise
{
  for (int i=0; i<=11; i++)
  {
  step1();
  step2();
  step3();
  step4();
  }
}
if (incomingbyte=='a') // anti-clockwise
{
  for (int i=0; i<=11; i++)
  {
  step3();
  step2();
  step1();
  step4(); 
  }
}
}
}