Trying to get rfid and infra red to work together

These two lots of code…… one …. Reads rfid cards and if “card a” is found it prints Card A to the screen …….if card b is found it prints Card B to the screen ….. the other code reads infra red remote and prints the value to the screen. What I need to do is if the rfid reader finds “card a “ then print card a to the screen but if it finds “card b “ then look for an infra red signal and print that value to the screen….. I have copied include and setup files from rfid code to the ir code but I am a bit stuck what to do next hope some one can help me with this

thanks for taking a look

#include <IRremote.h>
unsigned long startMillis;
unsigned int iter = 0;


int RECV_PIN = 12;

IRrecv irrecv(RECV_PIN);

decode_results results;



LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
static int lastState = 0;

byte data[5];  //For holding the ID we receive
int val = 0;
byte custa[5] = {
  0x4f,0x00,0x5f,0x06,0x1e};
byte custb[5] = {
  0x4f,0x00,0x5f,0x40,0x66};
void setup()
{

  Serial.begin(19200);





  GLCD.Init(NON_INVERTED);   // initialise the library
  GLCD.ClearScreen();  

  GLCD.ClearScreen();
  GLCD.SelectFont(System5x7);       // select fixed width system font 
  Serial.begin(19200);   



  Serial.begin(19200);     //just for now so i can see what's going on 
  Serial.print(0xFF,BYTE);  //Header
  Serial.print(0x01,BYTE);  //Reserved
  Serial.print(0x09,BYTE);  //Length (Command + Data)
  Serial.print(0x87,BYTE);  //Command (0x87 sets auto mode behavior
  Serial.print(0x01,BYTE);  //Data 1: Enable Auto-Read
  Serial.print(0x03,BYTE);  //Data 2: Mode – Parity decoded – Manchester RF/64
  Serial.print(0x02,BYTE);  //Data 3: Total number of block to be read (2)
  Serial.print(0x00,BYTE);  //Data 4: No password expected
  Serial.print(0x10,BYTE);  //Data 5: Password byte 1
  Serial.print(0x20,BYTE);  //Data 6: Password byte 2
  Serial.print(0x30,BYTE);  //Data 7: Password byte 3
  Serial.print(0x40,BYTE);  //Data 8: Password byte 4
  Serial.print(0x37,BYTE);  //Checksum

  delay(500);
  Serial.flush();
  Serial.println();


}

void loop()


/////////////////////////////////////////////////////////////////

{ 





  Serial.println(" Start");
  val = Serial.read();
  while (val != 0xff)
  {  //On Successful read, first byte will always be 0xFF
    val = Serial.read();
    delay(100);
  }

  //we already read the header (0xff)
  Serial.read();              // reserved
  Serial.read();              // length
  Serial.read();              // command (indicates tag data)
  data[0] = Serial.read();    // we read data 1
  data[1] = Serial.read();    // we read data 2
  data[2] = Serial.read();    // we read data 3
  data[3] = Serial.read();    // we read data 4
  data[4] = Serial.read();    // we read data 5

  Serial.read();              // checksum

  // Indentify RFID Card
  boolean cardb = true;
  boolean carda = true;

  for (int i=0; i<5; i++)
  {
    if (data[i] < 16) Serial.print("0");
    //Serial.print(data[i], HEX);

    //cross-check
    if (data[i] != custa[i]) carda = false;
    if (data[i] != custb[i]) cardb = false; 

    //////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

  }

  if (carda)      


  {



    Serial.println(" Card A");


  }

  if (cardb)      


  {



    Serial.println(" Card b");


  }









  else 

  {
    Serial.println(" end");
  }

}
/*
 * IRremote: IRrecvDemo - demonstrates receiving
 * IR codes with IRrecv
 * An IR detector/demodulator must be connected
 * to the input RECV_PIN.
 * Version 0.1 July, 2009
 * Copyright 2009 Ken Shirriff
 * http://arcfn.com
 */



#include <IRremote.h>

int RECV_PIN = 12;


IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
 

 
  
  
  Serial.begin(19200);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }





}

Rename the loop and setup functions loop1 and loop2, setup1 and setup2.
Then put them in the same file and have the setup call setup1 and setup2 and likewise the loops.
Then trim for any repeated lines, like the serial.begin.

thanks mike but…….that may make perfect sense to a lot of people but I am new to all this ?????…. How do I tell the program what loop to run and when …………thanks

please please can anyone help !!!!!!!!!!

i have a problem where I have to put two programs together a member of the forum as advised me …..

Rename the loop and setup functions loop1 and loop2, setup1 and setup2.
Then put them in the same file and have the setup call setup1 and setup2 and likewise the loops.
Then trim for any repeated lines, like the serial.begin

How do i do this ???????

Without seeing your code, difficult to say.

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

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

the code is in my last question thanks for you reply

maddave:
the code is in my last question thanks for you reply

Oh?

sorry i do not know how to link to another question on the forum ...what i mean i posted a question asking how to put two bits of code together …sorry about that

http://arduino.cc/forum/index.php/topic,78457.0.html

The program will only have one loop() function, you have renamed your existing functions so your loop function will look like:-

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

mmmmmmm write ....dont forget i am new at this ?????? how do i tell it what to run .....and when

how do i tell it what to run

I thought that is what I just showed you?

A sketch will always run a function called loop(), you put inside that function the functions or instructions you want to be executed.

I don't know what you don't understand.

dont forget i am new at this

No your not you have the two pieced of code that work so you must have run those.

thanks i will give it a go and let you know how i get on

Rename the "setup" in the first sketch as "setupIR", and the "loop" as "loopIR".
Rename the "setup" in the second sketch as "setupRFID", and the "loop" as "loopRFID".
Remove the "Serial.begin" from "setupRFID".

In your new sketch, from "setup" call "setupIR" and setupRFID", and from "loop" call "loopIR" and "loopRFID".

Moderator: Topics merged.

@OP: Please don't start a new thread asking the same question.

if i rename void setup() to void setuprfid() it will not compile

maddave:
if i rename void setup() to void setuprfid() it will not compile

Mad Dave, perhaps show the code which doesn't compile?

if i rename void setup() to void setuprfid() it will not compile

It will when you add the your new setup() function.

#include <LiquidCrystal.h>
#include <ks0108.h>  // library header
#include <Arial14.h>  // font definition for 14 point Arial font.
#include "SystemFont5x7.h"   // system font
#include "ArduinoIcon.h"     // bitmap  

unsigned long startMillis;
unsigned int iter = 0;






LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
static int lastState = 0;

byte data[5];  //For holding the ID we receive
int val = 0;
byte custa[5] = {0x4f,0x00,0x5f,0x40,0x66};
byte custb[5] = {
  0x4f,0x00,0x60,0x3d,0x58};

void setuprfid()
{


  GLCD.Init(NON_INVERTED);   // initialise the library
  GLCD.ClearScreen();  

  GLCD.ClearScreen();
  GLCD.SelectFont(System5x7);       // select fixed width system font 
  Serial.begin(19200);   



  Serial.begin(19200);     //just for now so i can see what's going on 
  Serial.print(0xFF,BYTE);  //Header
  Serial.print(0x01,BYTE);  //Reserved
  Serial.print(0x09,BYTE);  //Length (Command + Data)
  Serial.print(0x87,BYTE);  //Command (0x87 sets auto mode behavior
  Serial.print(0x01,BYTE);  //Data 1: Enable Auto-Read
  Serial.print(0x03,BYTE);  //Data 2: Mode – Parity decoded – Manchester RF/64
  Serial.print(0x02,BYTE);  //Data 3: Total number of block to be read (2)
  Serial.print(0x00,BYTE);  //Data 4: No password expected
  Serial.print(0x10,BYTE);  //Data 5: Password byte 1
  Serial.print(0x20,BYTE);  //Data 6: Password byte 2
  Serial.print(0x30,BYTE);  //Data 7: Password byte 3
  Serial.print(0x40,BYTE);  //Data 8: Password byte 4
  Serial.print(0x37,BYTE);  //Checksum

  delay(500);
  Serial.flush();
  Serial.println();



}

void looprfid()


/////////////////////////////////////////////////////////////////

{ 



bailout: // this is for the goto statment ( sorry but i can not thing of any other way but goto )


  val = Serial.read();
  while (val != 0xff)
  {  //On Successful read, first byte will always be 0xFF
    val = Serial.read();
    delay(100);
  }

  //we already read the header (0xff)
  Serial.read();              // reserved
  Serial.read();              // length
  Serial.read();              // command (indicates tag data)
  data[0] = Serial.read();    // we read data 1
  data[1] = Serial.read();    // we read data 2
  data[2] = Serial.read();    // we read data 3
  data[3] = Serial.read();    // we read data 4
  data[4] = Serial.read();    // we read data 5

  Serial.read();              // checksum

  // Indentify RFID Card
  boolean cardb = true;
  boolean carda = true;
 
  for (int i=0; i<5; i++)
  {
    if (data[i] < 16) Serial.print("0");
    //Serial.print(data[i], HEX);

    //cross-check
    if (data[i] != custa[i]) carda = false;
    if (data[i] != custb[i]) cardb = false; 
    
    //////////////////////////////////////////////////////////////////////////////////////////////
    //////////////////////////////////////////////////////////////////////////////////

  }

  if (carda)      


  {

  Serial.println("Card a"); 

  }
 if (cardb)

  {



  Serial.println("Card b"); 

}       


   

 
}

i am now willing to pay someone to put this code together name your price please help its taking over my life !!!!!!!!!!!!!!!!!