Sketch per provare i sensori di fine corsa
/* Effettua un'escursione completa di rotazione oraria e antioraria
 testando i due relè reed
*/
int motorPin1 = 8;
int motorPin2 = 9;
int motorPin3 = 10;
int motorPin4 = 11;
int motor_Speed = 10;
int motor_Step;
byte label1 = 0; //Semaforo rosso di inversione di marcia
byte SW1=0; // Relè reed fine corsa START
byte SW2=0; // Relè reed fine corsa END
 void setup() {
 pinMode(motorPin1, OUTPUT);
 pinMode(motorPin2, OUTPUT);
 pinMode(motorPin3, OUTPUT);
 pinMode(motorPin4, OUTPUT);
}
void loop() {

 SW1 = digitalRead(2); if(SW1==0){label1=1;} //Attiva semaforo rosso
 SW2 = digitalRead(3); if(SW2==0){label1=0;} //Disattiva semaforo rosso

if (SW1==1 && label1==0)
 {
 orario();
 }
 if (SW2==1 && label1==1)
 {
 antiorario();
 }
 }
void orario()
{
 digitalWrite(motorPin1, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay(motor_Speed);
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, LOW);
 delay(motor_Speed);
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin4, LOW);
 delay(motor_Speed);
 digitalWrite(motorPin1, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin4, HIGH);
 delay(motor_Speed);
}
void antiorario()
{
 digitalWrite(motorPin4, HIGH);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay(motor_Speed);
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, HIGH);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, LOW);
 delay(motor_Speed);
 digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, HIGH);
 digitalWrite(motorPin1, LOW);
 delay(motor_Speed);
  digitalWrite(motorPin4, LOW);
 digitalWrite(motorPin3, LOW);
 digitalWrite(motorPin2, LOW);
 digitalWrite(motorPin1, HIGH);
 delay(motor_Speed);
 }
 