can anybody combine the codes and give

please can anybody combine these codes together and give me i have given the link to download 2 codes -http://www.mediafire.com/file/eloojhqcbu99sya/arduino+code.txt

nikhil1234:
please can anybody combine these codes together and give me
i have given the link to download 2 codes -http://www.mediafire.com/file/eloojhqcbu99sya/arduino+code.txt

Have you tried to do it yourself ?

What is the combined program supposed to do ?

By the way, many people here will not follow a link to a random site so why not post the programs here ?

Hi, Some suggestions on how to do this HERE http://arduino-info.wikispaces.com/CombiningArduinoSketches

I’m sure someone here would be willing to combine two sketches for you - for a fee. If you want to hire someone, use the gigs and collaborations section.

We don’t write code for people here. You’ll usually find someone to help if you post what you’ve done and a description of how it’s not working. But you can’t just dump your project on the forums and expect someone to do it for you! (not for free at least)

Here are the two sketches combined.

void setup() {
  setup1();
  setup2();
}


void loop() {
  loop1();
  loop2();
}


#define encoder_a 2 //keep this on and interrupt pin
#define encoder_b 3 //keep this on and interrupt pin
#define motor_step1 9
#define motor_direction1 8
#define senzor_front 6
#define senzor_rear 7
#define load_button 4
#define eject_button 5
int home_position = 0;
int load_position = 0;
int pe_load = 0;


void setup1() {
  pinMode(encoder_a, INPUT);
  pinMode(encoder_b, INPUT);


  // disable pullup as we aren't using an open collector encoder
  digitalWrite(encoder_a, LOW);
  digitalWrite(encoder_b, LOW);


  //set up the various outputs
  pinMode(motor_step1, OUTPUT);
  pinMode(motor_direction1, OUTPUT);
  // then the senzors inputs
  pinMode(senzor_front, INPUT_PULLUP);
  pinMode(senzor_rear, INPUT_PULLUP);


  pinMode(load_button, INPUT_PULLUP);
  pinMode(eject_button, INPUT_PULLUP);
}


void loop1() {


  // Control platen position of boot up and move to front
  if (home_position == 0) {
    digitalWrite(motor_direction1, HIGH);
    TurnStepper();
    if (digitalRead(senzor_front) == LOW) {
      home_position = 1;
    }
  }


  // eject platen
  if (digitalRead(eject_button) == LOW) {
    home_position = 0;
  }


  // load platen
  if (digitalRead(load_button) == LOW) {
    load_position = 1;
  }
  if (load_position == 1) {
    digitalWrite(motor_direction1, LOW);
    TurnStepper();
    if (digitalRead(senzor_rear) == LOW) {
      load_position = 0;
      pe_load = 1;
    }
  }


}


void TurnStepper() {
  digitalWrite(motor_step1, HIGH);
  delayMicroseconds(40); //speed delay, the lower it is t
  digitalWrite(motor_step1, LOW);
  delayMicroseconds(40); //speed delay, the lower it is the faster
}




// second code


#define encoder_a 2 //keep this on and interrupt pin
#define encoder_b 3 //keep this on and interrupt pin
#define motor_step2 4 //can be any pin
#define motor_direction2 5 //can be any pin


volatile long motor_position, encoder;
unsigned long WaitReverse = 200; //<<<
unsigned long WaitForward = 200; //<<<
unsigned long StartReverse = micros(); //<<<
unsigned long StartForward = micros(); //<<<
unsigned long microsNow = micros(); //<<<


void setup2() {
  //set up the various outputs
  pinMode(motor_step2, OUTPUT);
  pinMode(motor_direction2, OUTPUT);


  // then the encoder inputs
  pinMode(encoder_a, INPUT);
  pinMode(encoder_b, INPUT);
  // enable pullup as we are using an open collector encoder
  digitalWrite(encoder_a, HIGH);
  digitalWrite(encoder_b, HIGH);


  // encoder pin on interrupt 0 (pin 2)
  attachInterrupt(0, encoderPinChangeA, CHANGE);
  // encoder pin on interrupt 1 (pin 3)
  attachInterrupt(1, encoderPinChangeB, CHANGE);
  encoder = 0; //reseet the encoder position to 0
}


void loop2() {
  //do stuff dependent on encoder position here
  //such as move a stepper motor to match encoder position
  //if you want to make it 1:1 ensure the encoder res matches the motor res by dividing/multiplying
  microsNow = micros(); //<<<


  if ((encoder > 0) && ((microsNow - StartReverse) > WaitReverse)) {
    digitalWrite(motor_direction2, HIGH);// move stepper in reverse
    digitalWrite(motor_step2, HIGH);
    digitalWrite(motor_step2, LOW);
    //delayMicroseconds(600); //_delay_us(200); //modify to alter speed <<<
    motor_position++;
    encoder = 0; //encoder--;
    StartReverse = micros(); //<<<
  }
  else if ((encoder < 0) && ((microsNow - StartForward) > WaitForward)) {
    digitalWrite (motor_direction2, LOW); //move stepper forward
    digitalWrite (motor_step2, HIGH);
    digitalWrite (motor_step2, LOW);
    //delayMicroseconds(600); //_delay_us(200); //modify to alter speed <<<
    motor_position--;
    encoder = 0; //encoder++;
    StartForward = micros(); //<<<
  }
}


void encoderPinChangeA() {
  if (digitalRead(encoder_a) == digitalRead(encoder_b)) {
    encoder--;
  }
  else {
    encoder++;
  }
}


void encoderPinChangeB() {
  if (digitalRead(encoder_a) != digitalRead(encoder_b)) {
    encoder--;
  }
  else {
    encoder++;
  }
}