User:Jdittman8063/ENES-100/project 1/Code Version 1

First attempt at improved version of code based on work done by Kmcgiver0970. Code for use in controlling motor and solenoid to open combo lock.

include  AF_Stepper motor(200, 2);

int led = 10; //set digital pin to 10

void setup{ pinMode (led, OUTPUT);              //for solenoid Serial.begin(9600);                     // set up Serial library at 9600 bps Serial.println("Stepper test!"); motor.setSpeed(10);                  // 10 rpm motor.step(200, FORWARD, SINGLE); motor.release; delay(1000); }

void loop { for (int a=1; a<40; a++){ for (int b=1; b<40; b++){ for (int c=1; c<40; c++){ //loop through all 64,000 theoretical combinations motor.step((a * 5), FORWARD, DOUBLE); delay(100); motor.step((a * 5), BACKWARD, DOUBLE); delay(100); motor.step((b * 5), BACKWARD, DOUBLE); delay(100); motor.step((c * 5), FORWARD, DOUBLE); delay(500);

//pull selenoid digitalWrite (led, HIGH); delay (500); digitalWrite (led, LOW); delay (500); //check position sensor if / else statement

//position at zero for next combination motor.step((c * 5), BACKWARD, DOUBLE); delay(100); motor.step((b * 5), FORWARD, DOUBLE); delay(500); //spin 2 full rotations to clear previous combination motor.step((200), FORWARD, DOUBLE); delay(1000); }     }   } }