/*Berdine Slave mode * inch button releasecamera */ #include #include AccelStepper stepper(1, A5, A4); // 1 = Easy Driver, A5 STEP pin, A4 DIR pin LiquidCrystal lcd(8, 9, 4, 5, 6, 7); //Pin assignments for SainSmart LCD Keypad Shield const int LIMIT = A1; // Limit switch connected to pin A1 const int SLAVE_PIN = 11; const int TOGG = 12; // Toggle switch connected to pin 12 const int INCH = 13; // Inch Push buton connected to pin 13 const int SHUT_PIN = 3; // shutter release cable const int RELEASE_TIME = 20; int oneMove = 100; // Distance of one slider's move void setup() { Serial.begin(9600); lcd.begin(16, 2); lcd.clear(); lcd.setCursor(0, 0); pinMode(SLAVE_PIN, INPUT_PULLUP); // sets the digital pin as input for the camera signal pinMode(LIMIT, INPUT_PULLUP); //Pin mode for the Limit switch pinMode(TOGG,INPUT); //Pin mode for the direction toggle switch pinMode(INCH,INPUT); //Pin mode for the inch push buttom pinMode(SHUT_PIN, OUTPUT); stepper.setMaxSpeed(1000); delay(2000); // wait a moment... lcd.print("Ready"); Serial.println("Ready"); } void loop() { if (digitalRead(INCH)== HIGH){ releaseCamera(); } if (digitalRead(SLAVE_PIN) == LOW){ Rail_Slave(); } } /** Actually release the camera */ void releaseCamera() { lcd.setCursor(15, 0); lcd.print((char)255); digitalWrite(SHUT_PIN, HIGH); delay(RELEASE_TIME); digitalWrite(SHUT_PIN, LOW); Serial.println("Shot"); lcd.setCursor(15, 0); lcd.print(" "); } /** Slave mode: When a pulse from Camera move a certain distance */ void Rail_Slave(){ Serial.println(oneMove); if (digitalRead(TOGG)== HIGH){ stepper.move(oneMove); // Distance of one slider's move while (stepper.distanceToGo() != 0){ if (digitalRead(LIMIT)== HIGH){ stepper.setSpeed(500); stepper.runSpeed(); } } } if ( digitalRead(TOGG)== LOW){ int CurPos = stepper.currentPosition (); int CCWMove = CurPos - oneMove; stepper.moveTo(CCWMove); // Distance of one slider's move while (stepper.currentPosition () != CCWMove){ if (digitalRead(LIMIT)== HIGH){ stepper.setSpeed(-500); stepper.runSpeed(); } } } }