Go Down

Topic: Please Need Help to combine two codes (Read 1 time) previous topic - next topic

zajebiscie

Please i still need help to combine my two codes...thanks

HazardsMind

It should just a simple drag and drop, but you have both codes using pins 11 and 2, so those will have to be changed. Another thing to watch out for is delays. The first one has two active delays but they are only 200 ms, which is not bad, but the second code also has two active delays that add up to 1 second, that might be bad. I dont know if time is an issue for you, but in total you have 1.2 seconds of delay. That 1.2 seconds it what it will take until the code is looped again.

Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

zajebiscie


It should just a simple drag and drop, but you have both codes using pins 11 and 2, so those will have to be changed. Another thing to watch out for is delays. The first one has two active delays but they are only 200 ms, which is not bad, but the second code also has two active delays that add up to 1 second, that might be bad. I dont know if time is an issue for you, but in total you have 1.2 seconds of delay. That 1.2 seconds it what it will take until the code is looped again.




Thanks for your help, please can you help me put them together. I do not mind if you assign the pins 11 and 2 to different pins number so they would not interfere with other, but it would be good if pin 2 still be the interrupt pin for wakeup (FSR).For the time, it matters a lot, because the whole idea for the system work faster, which ever time you think will be the best, i m willing to work with it...please help me.

HazardsMind

Try to do it on your own first, that way you get an idea of what is happening with the codes. Try to combine them then, come back and post the combined code along with any and all errors. Now if you have no idea of even where to start and are willing to pay someone to do it for you, then check out the Gigs and Collaboration page.

  http://arduino.cc/forum/index.php/board,26.0.html
Created Libraries:
TFT_Extension, OneWireKeypad, SerialServo, (UPD)WiiClassicController, VWID

zajebiscie

I combined these codes but it is not working for me..Please help me look into this code.

Code: [Select]
#include <Stepper.h>
#include <Adafruit_Fingerprint.h>
#if ARDUINO >= 100
#include <SoftwareSerial.h>
#else
#include <NewSoftSerial.h>
#endif
#include <avr/interrupt.h>
#include <avr/power.h>
#include <avr/sleep.h>
#include <avr/io.h>
//
const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
                                     // for your motor
boolean lock_state;
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, 8,9,10,11);         

int getFingerprintIDez();
void lock_motor();

// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
#if ARDUINO >= 100
SoftwareSerial mySerial(2, 3);
#else
NewSoftSerial mySerial(2, 3);
#endif

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void setup()
{

DDRD &= B00000011; // set Arduino pins 2 to 7 as inputs, leaves 0 & 1 (RX & TX) as is
DDRB = B00000000; // set pins 8 to 13 as inputs
PORTD |= B11111100; // enable pullups on pins 2 to 7
PORTB |= B11111111; // enable pullups on pins 8 to 13
pinMode(13,OUTPUT); // set pin 13 as an output so we can use LED to monitor
pinMode(11,OUTPUT);
digitalWrite(13,HIGH); // turn pin 13 LED on
digitalWrite(11,HIGH);

  lock_state = HIGH;
    // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  // initialize the serial port:
  //Serial.begin(9600);


  Serial.begin(9600);
  Serial.println("fingertest");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void loop()                     // run over and over again
{
// Stay awake for 1 second, then sleep.
// LED turns off when sleeping, then back on upon wake.
delay(100);
sleepNow();

  getFingerprintIDez();

}
//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void sleepNow(void)
{
  while(digitalRead(2)==LOW);
 
// Set pin 2 as interrupt and attach handler:
attachInterrupt(0, pinInterrupt, LOW);
delay(100);
//
// Choose our preferred sleep mode:
set_sleep_mode(SLEEP_MODE_IDLE);
//
// Set sleep enable (SE) bit:
sleep_enable();
  power_adc_disable();
  power_spi_disable();
  power_timer0_disable();
  power_timer1_disable();
  power_timer2_disable();
  power_twi_disable();

// Put the device to sleep:
digitalWrite(13,LOW); // turn LED off to indicate sleep
digitalWrite(11,HIGH);
sleep_mode();
//
// Upon waking up, sketch continues from this point.
sleep_disable();
digitalWrite(13,HIGH); // turn LED on to indicate awake
digitalWrite(11,LOW);
power_all_enable();

while(digitalRead(2)==LOW);

}
//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!

  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {


 
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
 

 
    Serial.println("Did not find a match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  } 

  // found a match!
  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK) {
    lock_motor();
    return -1;
  }

  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  {
    lock_motor();
    return -1;
  }

  // found a match!

  Serial.print("Found ID #"); Serial.print(finger.fingerID);
  Serial.print(" with confidence of "); Serial.println(finger.confidence);
  if (lock_state == HIGH){
      //This is for the motor
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
  delay(500);
  lock_state = LOW;
  }
  return finger.fingerID;

}

void lock_motor(){
  if (lock_state == LOW){
    // Is for the motor step one revolution in the other direction:
  Serial.println("counterclockwise");
  myStepper.step(-stepsPerRevolution);
  delay(500);
  lock_state = HIGH;
  }
}



//bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
void pinInterrupt(void)
{
sleep_disable();
detachInterrupt(0);
}

Go Up