How to make one variable out of more

Hi there,

I've got a question on variables. I'm using the following code for my RFID-Shield on Arduino:

/*
RFID Eval 13.56MHz Shield example sketch v10

Aaron Weiss, aaron at sparkfun dot com
OSHW license: http://freedomdefined.org/OSHW

works with 13.56MHz MiFare 1k tags

Based on hardware v13:
D7 -> RFID RX
D8 -> RFID TX
D9 -> XBee TX
D10 -> XBee RX

Note: RFID Reset attached to D13 (aka status LED)

Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/

Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
blinks the 'Found' LED and prints the serial number of the tag to the serial port
and the XBee port.
06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.

*/
#include <SoftwareSerial.h>

SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);

//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];

//INIT
void setup()
{
  Serial.begin(9600);
  Serial.println("Start");

  // set the data rate for the SoftwareSerial ports
  xbee.begin(9600);
  rfid.begin(19200);
  delay(10);
  halt();
}

//MAIN
void loop()
{
  read_serial();
}

void check_for_notag()
{
  seek();
  delay(10);
  parse();
  set_flag();

  if(flag = 1){
    seek();
    delay(10);
    parse();
  }
}

void halt()
{
 //Halt tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
}

void parse()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<11;i++){
        Str1[i]= rfid.read();
      }
    }
  }
}

void print_serial()
{
  if(flag == 1){
    //print to serial port
    Serial.print(Str1[8], HEX);
    Serial.print(Str1[7], HEX);
    Serial.print(Str1[6], HEX);
    Serial.print(Str1[5], HEX);
    Serial.println();
    delay(100);
    //check_for_notag();
  }
}

void read_serial()
{
  seek();
  delay(10);
  parse();
  set_flag();
  print_serial();
  delay(100);
}

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

void set_flag()
{
  if(Str1[2] == 6){
    flag++;
  }
  if(Str1[2] == 2){
    flag = 0;
  }
}

Now I'd like to make one new variable tagid which should consist of those variables in the if-part that are printed to the Serial Monitor:

void print_serial()
{
if(flag == 1){
//print to serial port
Serial.print(Str1[8], HEX);
Serial.print(Str1[7], HEX);
Serial.print(Str1[6], HEX);
Serial.print(Str1[5], HEX);
Serial.println();
delay(100);
//check_for_notag();
}
}

How do I have to do that?

Yours

arduino2013

sprintf()

Could you please add it to my code and post me the code after that?

Thanks a lot.

arduino2013

Could you please add it to my code and post me the code after that?

Could you please google sprintf() before you ask other people to do your work for you.

Could you at least explain what "one variable" you want to make from the contents of that array, which is already one variable.

arduino2013:
Could you please add it to my code and post me the code after that?

Thanks a lot.

arduino2013

I didn't realize this was my assignment. When is it due?

So do you mean that Str1 is already a variable?

what does Str1[8], HEX then mean?

Sorry I'm an absolute newbie in Arduino.

what does Str1[8], HEX then mean?

When in doubt, there's always the manual

So can you tell me the right syntax?

the thing I want to do is: Str1=tagid

http://www.cplusplus.com/reference/cstdio/sprintf/

the thing I want to do is: Str1=tagid

You already have data in Str1. Why do you want to overwrite it? What type is tagid? What are you then going to do with tagid that you can not do with Str1?

I want to create the variable tagid with the content of Str1 because I can remember that name better and I want to use tagid with my ethernetshield to be inserted into a mysql database.

I want to create the variable tagid with the content of Str1 because I can remember that name better

There is nothing magic about the name Str1. If you prefer tagid, then rename Str1.

and I want to use tagid with my ethernetshield to be inserted into a mysql database.

No. You want to use the CONTENTS OF tagid with... The contents of Str1 are the same, so use that, instead.

But what does the [8] in

Serial.print(Str1[8], HEX);

mean? I didn't find any explanations.

arduino2013:
But what does the [8] in

Serial.print(Str1[8], HEX);

mean? I didn't find any explanations.

Google "Arrays"

Thank you all for your competent help.

arduino2013