Combining 2 sketches for communicating via Serial-Solved!

Hi. This should combine a receiver and a server side of
2 Arduinos that are working fine together in one direction,
so each can do back what the other can do. That is:

  1. Light an LED to show that they're in proximity. (Serial letter 'H')
  2. Light another LED when a button is pressed on the other one. (Serial letter 'L')
  3. Light an Indicator LED to show the button has been pressed. (LED13)
    So far I have only got them to work as server and receiver.
    Only one can press a button and the other lights up.
    I combined the two sketches and now I can only get
    the 1. and the 3. to work properly. When I press the button
    nothing is triggered in the other, when I press it longer, the
    proximity indicating LED turns off, so I think that it does receive the 'L'
    after all. I'm posting the combined sketch here.
/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via xbee radios (for
 the post called 'Serial'.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one LED
 comes on on the other wearers piece, if a button is pressed, another LED
 lights up. This is the combined sketch for both machines. 'S' before the comments
 stands for 'comes from the server side'.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4 ;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProxInd

const int buttonPin = 5;     //S the number of the pushbutton pin
const int ButtInd =  13;      //S the number of the Button indicator LED pin

SoftwareSerial Serial (RXPin, TXPin);// defining the new serial name

int buttonState = 0;         //S variable for reading the pushbutton status

// a variable to read incoming serial data into
char incomingByte;
unsigned long TimerProxInd;
unsigned long TimerButtonLed;

void setup()                // definitions that are always true
{
  Serial.begin(9600);// set the data rate for the SoftwareSerial port
  pinMode(ProxInd, OUTPUT);
  pinMode(ButtonLed, OUTPUT);
  pinMode(buttonPin, INPUT);     //S declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'

}

void loop() // run over and over
{

  {
    Serial.print('H');                  //S send the letter H out
    delay(500);                       //S wait half a second
  }

  {  
    buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:
    if (buttonState == HIGH)    //S is the button not being pressed
      digitalWrite(ButtInd, LOW);//S leave the indicator LED off: 

    else                      //S otherwise
    {
      Serial.print('L');         //S send the letter 'L' over the wireless connection
      digitalWrite(ButtInd, HIGH);//S and turn LED on:
    }

    if (millis()-TimerProxInd>= 4000UL)

      digitalWrite(ProxInd,LOW);

    // see if there's incoming serial data:
    if (Serial.available() > 0) {
      // read the oldest byte in the serial buffer:
      incomingByte = (char)Serial.read();

      if (incomingByte == 'H') 
      {
        TimerProxInd=millis(),
        digitalWrite(ProxInd, HIGH);
      }
    }
    if 
      (Serial.read() == 'L')     // if you read the letter 'L'
    {
      digitalWrite(ButtonLed, HIGH);// set the ButtonLED on
      digitalWrite(ProxInd, HIGH);// set the LED on
      delay(1000);               // wait for a second
    }
    else
    {
      digitalWrite(ButtonLed, LOW);// turn the ButtonLED off
    }
  }
}

Now if I leave the command right at the beginning

{
    Serial.print('H');                  //S send the letter H out
    delay(500);                       //S wait half a second
  }

out and upload that one to the receiver, leaving
the combined sketch as it is for the server side, everything works fine.
The Button LED triggering is not blocked.
But then I don't have 2 way communication.
What did I do wrong?

 (Serial.read() == 'L')     //

Why aren't you comparing against "incomingByte", instead of reading a character that may not have arrived?

Using the auto-format tool might make your code a little easier to read, as would getting rid of the excess braces.

Of course.

    if 
      (incomingByte == 'L')     // if you read the letter 'L'

That makes the program working fully on both sides for the first time!
Great.
Took me 2 days checking until I posted it. Should have done it earlier!
Now there's still a little limp in the program as you know...
When I press the button on the one side, the corresponding LED
comes on with a lag of about a second. That shouldn't be so bad.
But the more complex the sketches went-
having them now combined successfully- it now shows that I never
got to get to the point to avoid 'delay' fully.
Because sometimes when I press the button, the LED doesn't come on
at all and then several seconds later, multiple times- as many times
as I have pressed the button that is.
I know the sketch is quite complex now, but do you think you could
give it another try to have the button-serial-LED sequence more
responsive? And should I post this as a new topic or maybe under
the old one?
The full working code for now is:

/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via xbee radios (for
 the post called 'Serial'.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one LED
 comes on on the other wearers piece, if a button is pressed, another LED
 lights up. This is the combined sketch for both machines. 'S' before the comments
 stands for 'comes from the server side'. This code is working with some lags and
 misses of the button-serial-led sequence, probably due to the use of 'delay'.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4 ;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProxInd

const int buttonPin = 5;     //S the number of the pushbutton pin
const int ButtInd =  13;      //S the number of the Button indicator LED pin

SoftwareSerial Serial (RXPin, TXPin);// defining the new serial name

int buttonState = 0;         //S variable for reading the pushbutton status

// a variable to read incoming serial data into
char incomingByte;
unsigned long TimerProxInd;
unsigned long TimerButtonLed;

void setup()                // definitions that are always true
{
  Serial.begin(9600);// set the data rate for the SoftwareSerial port
  pinMode(ProxInd, OUTPUT);
  pinMode(ButtonLed, OUTPUT);
  pinMode(buttonPin, INPUT);     //S declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'

}

void loop() // run over and over
{

  {
    Serial.print('H');                  //S send the letter H out
    delay(500);                       //S wait half a second
  }

  {  
    buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:
    if (buttonState == HIGH)    //S is the button not being pressed
      digitalWrite(ButtInd, LOW);//S leave the indicator LED off: 

    else                      //S otherwise
    {
      Serial.print('L');         //S send the letter 'L' over the wireless connection
      digitalWrite(ButtInd, HIGH);//S and turn LED on:
    }

    if (millis()-TimerProxInd>= 4000UL)

      digitalWrite(ProxInd,LOW);

    // see if there's incoming serial data:
    if (Serial.available() > 0) {
      // read the oldest byte in the serial buffer:
      incomingByte = (char)Serial.read();

      if (incomingByte == 'H') 
      {
        TimerProxInd=millis(),
        digitalWrite(ProxInd, HIGH);
      }
    }
    if 
      (incomingByte == 'L')     // if you read the letter 'L'
    {
      digitalWrite(ButtonLed, HIGH);// set the ButtonLED on
      digitalWrite(ProxInd, HIGH);// set the LED on
      delay(1000);               // wait for a second
    }
    else
    {
      digitalWrite(ButtonLed, LOW);// turn the ButtonLED off
    }
  }
}

Moderator edit: CODE TAGS again.

Concerning manners.
I did 'autoformat' as you suggested earlier, just before posting.
I do that regularly now. It must have not picked up on the
excess brackets. I might need to look after it better myself.
Also I did use the hash button to insert the code both times.
There is always : code /code with brackets ``
I'll preview my next post before. I like good manners, too.
But thanks for pointing it out.

So we finished eradicating 'delay' out of my receiver code beautifully in
http://arduino.cc/forum/index.php/topic,110172.30.html
with the help of cyclegadget and AWOL. It works great with the below
posted Server code.
Now I only needed to combine the receiver- with my server code like I did above
already to the old ones with the help of AWOL.
BUT: This new combined code only works as a receiver when the other
one has my server code.
In the moment I upload it to the previous server circuit to make them both equal,
The following things happen:
The Proximity LED starts fine, the button LED takes ages to come on
and then it doesn't stop. When the other Board is switched off or is far
away, both LEDs turn off after a while.

  1. The great new receiver code that works with the server code that follows:
/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one ProximityIndicatorLED
 comes on on the other wearers piece, if a button is pressed, another ButtonLED
 lights up. This is the receiver side.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin
int ledState = LOW;
int ledState2 = LOW;
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name
char incomingByte;    // a variable to read incoming serial data into
unsigned long TimerProxInd;
unsigned long TimerButtonLed;

void setup()                // definitions that are always true
{
  Serial.begin(9600);
 // xbee.begin(9600);// set the data rate for the SoftwareSerial port
  xbee.begin(9600);
  pinMode(ProxInd, OUTPUT);
  pinMode(ButtonLed, OUTPUT);
}

void loop() // run over and over
{
  unsigned long newtime = millis();
  // see if there's incoming serial data:
  if (xbee.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = (char)xbee.read();
    xbee.println(incomingByte);
  
  
  // if it's a capital H (ASCII 72), turn on the LED:
  if (incomingByte == 'H') 
  {
    TimerProxInd = newtime,
    digitalWrite(ProxInd, HIGH);
    ledState = HIGH;
    Serial.println("I got an H");
    
  }
  }
  if (newtime - TimerProxInd >= 1000UL && ledState == HIGH)
  {
    digitalWrite(ProxInd,LOW);
    ledState = LOW;
    Serial.println("time is up for TimerProxInd");
  
 
  }

  // if it's a capital L, turn on the LED:
  if (incomingByte == 'L') 
  {
    TimerButtonLed = newtime; 
    digitalWrite(ButtonLed, HIGH);
    ledState2 = HIGH;
    Serial.println("I got a L");
  }
  if (newtime - TimerButtonLed >= 1000UL && ledState2 == HIGH)
  {
    digitalWrite(ButtonLed, LOW);
    ledState2 = LOW;
    Serial.println("time is up for ButtonLed");
  }
}
  1. Now the server code with which the first one works and that I want to combine:
/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one LED
 comes on on the other wearers piece, if a button is pressed, another LED
 lights up. This is the server side.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int buttonPin = 5;     // the number of the pushbutton pin
const int ButtInd =  13;      // the number of the indicator LED pin
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name

int buttonState = 0;         // variable for reading the pushbutton status

void setup()                 // definitions that are always true
{                
  xbee.begin(9600);         // initialize the communication radio communication
  pinMode(ButtInd, OUTPUT);	// declare LED as output
  pinMode(buttonPin, INPUT);     // declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //default pin state to HIGH or 'on'
}

void loop()                       // run over and over
{
  xbee.print('H');                  // send the letter H out
  delay(200);                       // wait half a second

  buttonState = digitalRead(buttonPin);// read the state of the pushbutton value:
  if (buttonState == HIGH)    // is the button not being pressed
    digitalWrite(ButtInd, LOW);// leave the ButtonIndicator LED off: 

  else                      // otherwise
  {
    xbee.print('L');         // send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);// and turn ButtonIndicatorLED on:
  }
}
  1. And last the attempted combination of the both: What did I do wrong?
/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one ProximityIndicatorLED
 comes on on the other wearers piece, if a button is pressed, another ButtonLED
 lights up. This is supposed to be the combined sketch so that both machines can
 do the same to each other. S before the comment stands for 'from server code'.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin

const int buttonPin = 5;     // S the number of the pushbutton pin
const int ButtInd =  13;      //S  the number of the indicator LED pin
int buttonState = 0;         // S variable for reading the pushbutton status

int ledState = LOW;
int ledState2 = LOW;
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name
char incomingByte;    // a variable to read incoming serial data into
unsigned long TimerProxInd;
unsigned long TimerButtonLed;

void setup()                // definitions that are always true
{
  Serial.begin(9600);
  // xbee.begin(9600);// set the data rate for the SoftwareSerial port
  xbee.begin(9600);
  pinMode(ProxInd, OUTPUT);
  pinMode(ButtonLed, OUTPUT);
  
  pinMode(ButtInd, OUTPUT);	//S  declare LED as output
  pinMode(buttonPin, INPUT);     //S  declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'
  
}

void loop() // run over and over
{
 { 
  xbee.print('H');                  //S send the letter H out
  delay(200);                       //S wait half a second
}
  buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:
  if (buttonState == HIGH)    //S is the button not being pressed
    digitalWrite(ButtInd, LOW);//S leave the ButtonIndicatorLED off: 

  else                      //S otherwise
  {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
  }
  
  unsigned long newtime = millis();
  // see if there's incoming serial data:
  if (xbee.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = (char)xbee.read();
    xbee.println(incomingByte);


    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') 
    {
      TimerProxInd = newtime,
      digitalWrite(ProxInd, HIGH);
      ledState = HIGH;
      Serial.println("I got an H");

    }
  }
  if (newtime - TimerProxInd >= 1000UL && ledState == HIGH)
  {
    digitalWrite(ProxInd,LOW);
    ledState = LOW;
    Serial.println("time is up for TimerProxInd");


  }

  // if it's a capital L, turn on the LED:
  if (incomingByte == 'L') 
  {
    TimerButtonLed = newtime; 
    digitalWrite(ButtonLed, HIGH);
    ledState2 = HIGH;
    Serial.println("I got a L");
  }
  if (newtime - TimerButtonLed >= 1000UL && ledState2 == HIGH)
  {
    digitalWrite(ButtonLed, LOW);
    ledState2 = LOW;
    Serial.println("time is up for ButtonLed");
  }
}

(you can replace XBee with Serial and put two Arduinos
together via RxTx if you want to try it out.)

I found 2 problems in your server code.

This part prints ('H') every pass through the loop and delays the sketch 200ms every time by. Is this what you want?

void loop()                       // run over and over
{
  xbee.print('H');                  // send the letter H out
  delay(200);

This part need fixed.

if (buttonState == HIGH)    //S is the button not being pressed
    digitalWrite(ButtInd, LOW);//S leave the ButtonIndicatorLED off: 

  else                      //S otherwise
  {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
  }

Needs to be like this, look at the brackets and compare to your code.

if (pinFiveInput < 500)
{
  // action A
}
else
{
  // action B
}
  1. The server bit of the Code marked "//S" in the comments is much older than the receiver bit that we did together.
    I wanted to try first to put all the code of the working server code into the working receiver code and after that work on getting rid of the delay afterwards.
    The server bit of the system is only supposed to send a steady signal (H) that makes it visible to the other system, and a signal upon pressing the button (L). (Proximity, 2 way communication) So they both need both parts.
  2. The {} brackets, I thought, are not needed when you only have one line after the 'if', but I tried to put them in like you suggested- no change though.
/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one ProximityIndicatorLED
 comes on on the other wearers piece, if a button is pressed, another ButtonLED
 lights up. This is supposed to be the combined sketch so that both machines can
 do the same to each other. S before the comment stands for 'from server code'.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin

const int buttonPin = 5;     // S the number of the pushbutton pin
const int ButtInd =  13;      //S  the number of the indicator LED pin
int buttonState = 0;         // S variable for reading the pushbutton status

int ledState = LOW;
int ledState2 = LOW;
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name
char incomingByte;    // a variable to read incoming serial data into
unsigned long TimerProxInd;
unsigned long TimerButtonLed;

void setup()                // definitions that are always true
{
  Serial.begin(9600);
  // xbee.begin(9600);// set the data rate for the SoftwareSerial port
  xbee.begin(9600);
  pinMode(ProxInd, OUTPUT);
  pinMode(ButtonLed, OUTPUT);

  pinMode(ButtInd, OUTPUT);	//S  declare LED as output
  pinMode(buttonPin, INPUT);     //S  declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'

}

void loop() // run over and over
{
  { 
    xbee.print('H');                  //S send the letter H out
    delay(200);                       //S wait half a second
  }
  buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:
  if (buttonState == HIGH)    //S is the button not being pressed
  {
    digitalWrite(ButtInd, LOW);//S leave the ButtonIndicatorLED off: 
  }
  else                      //S otherwise
  {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
  }

  unsigned long newtime = millis();
  // see if there's incoming serial data:
  if (xbee.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = (char)xbee.read();
    xbee.println(incomingByte);


    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') 
    {
      TimerProxInd = newtime,
      digitalWrite(ProxInd, HIGH);
      ledState = HIGH;
      Serial.println("I got an H");

    }
  }
  if (newtime - TimerProxInd >= 1000UL && ledState == HIGH)
  {
    digitalWrite(ProxInd,LOW);
    ledState = LOW;
    Serial.println("time is up for TimerProxInd");

  }

  // if it's a capital L, turn on the LED:
  if (incomingByte == 'L') 
  {
    TimerButtonLed = newtime; 
    digitalWrite(ButtonLed, HIGH);
    ledState2 = HIGH;
    Serial.println("I got a L");
  }
  if (newtime - TimerButtonLed >= 1000UL && ledState2 == HIGH)
  {
    digitalWrite(ButtonLed, LOW);
    ledState2 = LOW;
    Serial.println("time is up for ButtonLed");
  }
}

I hope I am not helping you too much but, here is your code reworked. It needs tested still. You will find the print H part now has blink without delay style. To do that a new variable had to be added named Timerprint. I fixed the if, else part and put the if "L" portion inside of the serial available "if".

Look it over carefully and ask questions for anything you don't understand.

/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one ProximityIndicatorLED
 comes on on the other wearers piece, if a button is pressed, another ButtonLED
 lights up. This is supposed to be the combined sketch so that both machines can
 do the same to each other. S before the comment stands for 'from server code'.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin

const int buttonPin = 5;     // S the number of the pushbutton pin
const int ButtInd =  13;      //S  the number of the indicator LED pin
int buttonState = 0;         // S variable for reading the pushbutton status

int ledState = LOW;
int ledState2 = LOW;
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name
char incomingByte;    // a variable to read incoming serial data into
unsigned long TimerProxInd;
unsigned long TimerButtonLed;
unsigned long Timerprint = 0;    //timer for printing H

void setup()                // definitions that are always true
{
  Serial.begin(9600);
  // xbee.begin(9600);// set the data rate for the SoftwareSerial port
  xbee.begin(9600);
  pinMode(ProxInd, OUTPUT);
  pinMode(ButtonLed, OUTPUT);

  pinMode(ButtInd, OUTPUT);	//S  declare LED as output
  pinMode(buttonPin, INPUT);     //S  declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'
}

void loop() // run over and over
{
  unsigned long newtime = millis();

  if (newtime - Timerprint >= 200UL)    //S wait half a second
  { 
    xbee.print('H');                  //S send the letter H out
    Timerprint = newtime;            //update timeer
  }

  buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:
  
  if (buttonState == HIGH)    //S is the button not being pressed
  {
    digitalWrite(ButtInd, LOW);//S leave the ButtonIndicatorLED off: 
  }
  else                      //S otherwise
  {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
  }

  // see if there's incoming serial data:
  if (xbee.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = (char)xbee.read();
    xbee.println(incomingByte);

    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') 
    {
      TimerProxInd = newtime,
      digitalWrite(ProxInd, HIGH);
      ledState = HIGH;
      Serial.println("I got an H");
    }

    // if it's a capital L, turn on the LED:
    if (incomingByte == 'L') 
    {
      TimerButtonLed = newtime; 
      digitalWrite(ButtonLed, HIGH);
      ledState2 = HIGH;
      Serial.println("I got a L");
    }
  }

  if (newtime - TimerProxInd >= 1000UL && ledState == HIGH)
  {
    digitalWrite(ProxInd,LOW);
    ledState = LOW;
    Serial.println("time is up for TimerProxInd");
  }

  if (newtime - TimerButtonLed >= 1000UL && ledState2 == HIGH)
  {
    digitalWrite(ButtonLed, LOW);
    ledState2 = LOW;
    Serial.println("time is up for ButtonLed");
  }
}

No, you can't possibly help me too much. I'm a jewelry designer and
therefore the project is a little off the charts for me. I need all
the help I can get with the electronics. Thank you.
I do understand timerprint basically.

Now the proximityLed that acts on the letter 'H' isn't beginning
to stay on constantly.
Even after I have changed the mills to from 200 to 500 or 1000. Every time after a while, though, it has stabilized stays on
and then the ButtonLed starts coming on irregularly and long
as well!
Without me ever having pressed the button on the other
machine.
The Serial even reads an 'L' even after I have disconnected
the button altogether.

Then I tried to rename the letters to 'A' and 'B'
on one side of the system and vice versa to read only them. Maybe
the circuit reads its own Serial? No. That didn't change anything.

I tried the new sketch out as a pure receiver with the old server code
on the other end and also with the updated server code (with Timerprint instead of delay) and it works fine as receiver. Only not when it's on both machines, though.
Needless to say I tried to switch machines, plus they are 100% equal.
How can it be so hard to combine 2 sketches?

The code here, just to mention, the updated server code using 'Timerprint' instead of 'delay'.

/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one LED
 comes on on the other wearers piece, if a button is pressed, another LED
 lights up. This is the server side.
 */
#include <SoftwareSerial.h>        // use these specified set of commands

const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
const int buttonPin = 5;     // the number of the pushbutton pin
const int ButtInd =  13;      // the number of the indicator LED pin
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name

int buttonState = 0;         // variable for reading the pushbutton status
unsigned long Timerprint = 0;    //timer for printing H

void setup()                 // definitions that are always true
{                
  xbee.begin(9600);         // initialize the communication radio communication
  pinMode(ButtInd, OUTPUT);	// declare LED as output
  pinMode(buttonPin, INPUT);     // declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //default pin state to HIGH or 'on'
}

void loop()                       // run over and over
{
  unsigned long newtime = millis();

  if (newtime - Timerprint >= 500UL)    //S wait half a second
  {
    xbee.print('H');                  // send the letter H out
    Timerprint = newtime;            //update timer
  }
  buttonState = digitalRead(buttonPin);// read the state of the pushbutton value:
  if (buttonState == HIGH)    // is the button not being pressed
    digitalWrite(ButtInd, LOW);// leave the indicator LED off: 

  else                      // otherwise
  {
    xbee.print('L');         // send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);// and turn LED on:
  }
}

I just started programming Arduino mid-last year therefore, I call myself a Novice and I still make mistakes.

Is it correct that you have 2 lilypad boards that are identical? You want them to light LED when they connect to each other through the wireless X-bee. Lastly, each user can push a button to make an additional LED light on the other persons lilypad.

The last sketch I wrote was intended to work with both boards if the above is correct. I could have created some new errors as I do make mistakes. I will look over it again later today.

I see my mistake. I thought the 2 boards were identical but, now after looking at your pin numbers that seems to not be correct.

Earlier versions ran with LED13 to try out, but since long
this is the correct Pin assignment on both boards.
You had that right as far as I know in your last sketch.
With additional comments here.

const int RXPin = A4;     // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX

const int ButtonLed = 9;     // the number of the PushLed pin ( that comes on when there's an 'L' read on Serial)
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin (that comes on when there's a steady 'H' or Serial input)

const int buttonPin = 5;     // S the number of the pushbutton pin (where the button sits (without a resistor, that's why the HIGH-LOW is the
                                                                                                                                      other way round - works fine like that)
const int ButtInd =  13;      //S  the number of the indicator LED pin (that indicates on the same board that the button has been pressed)

I need you too check your button. If it is not working properly the sketch will be tied up printing "L" over and over.

Use this code it has all the same variables but, will only test the button part of the Loop();

#include <SoftwareSerial.h>        // use these specified set of commands
//////////////////SERIAL PINS//////////////////
const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name
/////////////////LED PINS//////////////////////
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin
const int ButtInd =  13;      //S  the number of the indicator LED pin
////////////////BUTTON PINS/////////////////////
const int buttonPin = 5;     // S the number of the pushbutton pin
////////////////STATE VARIABLES////////////////
int buttonState = 0;         // S variable for reading the pushbutton status
int ledState = LOW;
int ledState2 = LOW;
////////////////TIMER VARIABLES///////////////
unsigned long TimerProxInd;
unsigned long TimerButtonLed;
unsigned long Timerprint = 0;    //timer for printing H
///////////////SERIAL VARIABLES//////////////
char incomingByte;    // a variable to read incoming serial data into

///////////////SET-UP////////////////////////
void setup()                // definitions that are always true
{
  Serial.begin(9600);
  xbee.begin(9600);// set the data rate for the SoftwareSerial port
  pinMode(ProxInd, OUTPUT);   // the number of the ProximityIndicatorLED pin (that comes on when there's a steady 'H' or Serial input)
  pinMode(ButtonLed, OUTPUT); // the number of the PushLed pin ( that comes on when there's an 'L' read on Serial)
  pinMode(ButtInd, OUTPUT);	//S  declare LED as output the number of the indicator LED pin 
  //(that indicates on the same board that the button has been pressed)
  pinMode(buttonPin, INPUT);     //S  declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'
}

void loop() // run over and over
{
  
/////////////////////////CHECK THE BUTTON//////////////////////
  buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:

  if (buttonState == HIGH)    //S is the button not being pressed
  {
    digitalWrite(ButtInd, LOW);//S leave the ButtonIndicatorLED off: 
  }
  else                      //S otherwise
  {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
  }
}

Ok. I put that one on one circuit, press the button and see:

  1. The ButtonInd (LED13) is coming on and off when I let it go.
  2. On the other circuit, on which is your last combined sketch, Serial reads nicely:
    I got a L
    I got a L
    I got a L
    I got a L
    time is up for ButtonLed

and stops correctly when I let go.
So far so good.

I removed most of the debugging prints and I put a timer on the x.bee.print 'L' part of the code. I think that maybe the code was too busy printing to serial to have time for the rest of the sketch. Also, I think the button push was sending many L's instead of just one.

Here is the part of the code were a timer is added to the print L section. It will allow you too send one L every two seconds if you hold the button.

 if (newtime - TimerprintL >= 2000UL)    //S wait 2 seconds between sending L
    {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
    TimerprintL = newtime;            //update timer
    }

The latest code to try.

/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one ProximityIndicatorLED
 comes on on the other wearers piece, if a button is pressed, another ButtonLED
 lights up. This is supposed to be the combined sketch so that both machines can
 do the same to each other. S before the comment stands for 'from server code'.
 
 */
#include <SoftwareSerial.h>        // use these specified set of commands
//////////////////SERIAL PINS//////////////////
const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name
/////////////////LED PINS//////////////////////
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin
const int ButtInd =  13;      //S  the number of the indicator LED pin
////////////////BUTTON PINS/////////////////////
const int buttonPin = 5;     // S the number of the pushbutton pin
////////////////STATE VARIABLES////////////////
int buttonState = 0;         // S variable for reading the pushbutton status
int ledState = LOW;
int ledState2 = LOW;
////////////////TIMER VARIABLES///////////////
unsigned long TimerProxInd;
unsigned long TimerButtonLed;
unsigned long TimerprintH = 0;    //timer for printing H
unsigned long TimerprintL = 0;    //timer for printing L
///////////////SERIAL VARIABLES//////////////
char incomingByte;    // a variable to read incoming serial data into

///////////////SET-UP////////////////////////
void setup()                // definitions that are always true
{
  Serial.begin(9600);
  xbee.begin(9600);// set the data rate for the SoftwareSerial port
  pinMode(ProxInd, OUTPUT);   // the number of the ProximityIndicatorLED pin (that comes on when there's a steady 'H' or Serial input)
  pinMode(ButtonLed, OUTPUT); // the number of the PushLed pin ( that comes on when there's an 'L' read on Serial)
  pinMode(ButtInd, OUTPUT);	//S  declare LED as output the number of the indicator LED pin 
  //(that indicates on the same board that the button has been pressed)
  pinMode(buttonPin, INPUT);     //S  declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'
}

void loop() // run over and over
{
  unsigned long newtime = millis();

  if (newtime - TimerprintH >= 900UL)    //S wait 900ms
  { 
    xbee.print('H');                  //S send the letter H out
    TimerprintH = newtime;            //update timer
  }
/////////////////////////CHECK THE BUTTON//////////////////////
  buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:

  if (buttonState == HIGH)    //S is the button not being pressed
  {
    digitalWrite(ButtInd, LOW);//S leave the ButtonIndicatorLED off: 
  }
  else                      //S otherwise
  {
    if (newtime - TimerprintL >= 2000UL)    //S wait 2 seconds between sending L
    {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
    TimerprintL = newtime;            //update timer
    }
  }

//////////////////////////CHECK FOR INCOMING SERIAL///////////
  // see if there's incoming serial data:
  if (xbee.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = (char)xbee.read();
    xbee.println(incomingByte);

    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') 
    {
      TimerProxInd = newtime,
      digitalWrite(ProxInd, HIGH);
      ledState = HIGH;
      }

    // if it's a capital L, turn on the LED:
    if (incomingByte == 'L') 
    {
      TimerButtonLed = newtime; 
      digitalWrite(ButtonLed, HIGH);
      ledState2 = HIGH;
      }
  }

  if (newtime - TimerProxInd >= 2000UL && ledState == HIGH)
  {
    digitalWrite(ProxInd,LOW);
    ledState = LOW;
    Serial.println("time is up for TimerProxInd");
  }

  if (newtime - TimerButtonLed >= 1000UL && ledState2 == HIGH)
  {
    digitalWrite(ButtonLed, LOW);
    ledState2 = LOW;
    Serial.println("time is up for ButtonLed");
  }
}

Thanks so much, but again: Works fine as receiver-
When I put it on both circuits, the Proximity LED comes on fine and stays on.
But:
The ButtonLed comes on, however, every two seconds, sometimes
more often, without me ever pressing the button at all.
Serial also reads now only "time is up for ButtonLed" all the time-
nothing else.

There was one old part of the code still in the sketch that could have been causing a "circle of repeats" for lack of a better name:

xbee.println(incomingByte);

Here is the newest code without the above:

/*
  By Alexandra da Fonseca-Klein, Digital Jewellery project,
 For interactive Jewellery 'proximity sensing hearts'
 www.ADFK.co.uk; 2012
 2 Arduino Lilypad Simple Boards are connected via Xbee Series 2 radios.
 The Simple Board lacks Rx/Tx, therefore the use of SoftwareSerial.
 If the 2 wearers are within reach (30 feet approx) one ProximityIndicatorLED
 comes on on the other wearers piece, if a button is pressed, another ButtonLED
 lights up. This is supposed to be the combined sketch so that both machines can
 do the same to each other. S before the comment stands for 'from server code'.
 
 */
#include <SoftwareSerial.h>        // use these specified set of commands
//////////////////SERIAL PINS//////////////////
const int RXPin = A4;              // setting the pin to RX
const int TXPin = A5;              // setting the pin to TX
SoftwareSerial xbee (RXPin, TXPin);// defining the new serial name
/////////////////LED PINS//////////////////////
const int ButtonLed = 9;     // the number of the PushLed pin
const int ProxInd =  11;      // the number of the ProximityIndicatorLED pin
const int ButtInd =  13;      //S  the number of the indicator LED pin
////////////////BUTTON PINS/////////////////////
const int buttonPin = 5;     // S the number of the pushbutton pin
////////////////STATE VARIABLES////////////////
int buttonState = 0;         // S variable for reading the pushbutton status
int ledState = LOW;
int ledState2 = LOW;
////////////////TIMER VARIABLES///////////////
unsigned long TimerProxInd;
unsigned long TimerButtonLed;
unsigned long TimerprintH = 0;    //timer for printing H
unsigned long TimerprintL = 0;    //timer for printing L
///////////////SERIAL VARIABLES//////////////
char incomingByte;    // a variable to read incoming serial data into

///////////////SET-UP////////////////////////
void setup()                // definitions that are always true
{
  Serial.begin(9600);
  xbee.begin(9600);// set the data rate for the SoftwareSerial port
  pinMode(ProxInd, OUTPUT);   // the number of the ProximityIndicatorLED pin (that comes on when there's a steady 'H' or Serial input)
  pinMode(ButtonLed, OUTPUT); // the number of the PushLed pin ( that comes on when there's an 'L' read on Serial)
  pinMode(ButtInd, OUTPUT);	//S  declare LED as output the number of the indicator LED pin 
  //(that indicates on the same board that the button has been pressed)
  pinMode(buttonPin, INPUT);     //S  declare pushbutton as input
  digitalWrite(buttonPin, HIGH);  //S default pin state to HIGH or 'on'
}

void loop() // run over and over
{
  unsigned long newtime = millis();

  if (newtime - TimerprintH >= 900UL)    //S wait 900ms
  { 
    xbee.print('H');                  //S send the letter H out
    TimerprintH = newtime;            //update timer
  }
/////////////////////////CHECK THE BUTTON//////////////////////
  buttonState = digitalRead(buttonPin);//S read the state of the pushbutton value:

  if (buttonState == HIGH)    //S is the button not being pressed
  {
    digitalWrite(ButtInd, LOW);//S leave the ButtonIndicatorLED off: 
  }
  else                      //S otherwise
  {
    if (newtime - TimerprintL >= 2000UL)    //S wait 2 seconds between sending L
    {
    xbee.print('L');         //S send the letter 'L' over the wireless connection
    digitalWrite(ButtInd, HIGH);//S and turn ButtonIndicatorLED on:
    TimerprintL = newtime;            //update timer
    }
  }

//////////////////////////CHECK FOR INCOMING SERIAL///////////
  // see if there's incoming serial data:
  if (xbee.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = (char)xbee.read();
    
    // if it's a capital H (ASCII 72), turn on the LED:
    if (incomingByte == 'H') 
    {
      TimerProxInd = newtime,
      digitalWrite(ProxInd, HIGH);
      ledState = HIGH;
      }

    // if it's a capital L, turn on the LED:
    if (incomingByte == 'L') 
    {
      TimerButtonLed = newtime; 
      digitalWrite(ButtonLed, HIGH);
      ledState2 = HIGH;
      }
  }

  if (newtime - TimerProxInd >= 2000UL && ledState == HIGH)
  {
    digitalWrite(ProxInd,LOW);
    ledState = LOW;
    Serial.println("time is up for TimerProxInd");
  }

  if (newtime - TimerButtonLed >= 1000UL && ledState2 == HIGH)
  {
    digitalWrite(ButtonLed, LOW);
    ledState2 = LOW;
    Serial.println("time is up for ButtonLed");
  }
}

Awesome!
Works on both machines now.
Thank you!
One question: Why do we use TimerprintH instead of Timerprint now?
That doesn't refer to the 'H' we're sending, does it?

Why do we use TimerprintH instead of Timerprint now?

I should have mentioned it but, I was deep in thought looking for the problems.

That doesn't refer to the 'H' we're sending, does it?

Yes it does.

I needed a timer for printing L so, I figured the best logic was to have TimerprintH and TimerprintL so that I would know that TimerprintH is for timing the prints of H, and TimerprintL is for timing the prints of L.

Good idea.
I thought so, too.
You have officially solved this problem.
Is there a marker 'solved' on the Forum?

By the way: Since the two proximity-sensing
and 2 way communicating prototypes are
now exactly the same, I need
to give each of them a slightly different
actuator.
Machine one has a colour-
changing (built-in feature) LED as Proximity LED
(That's why it was so important to leave the LED
on without stop)
and a vibe board as Button actuator.
They work already all the time on the system.
Now on the other one I have now a
heart-beat simulating pulse of a red LED as the Proximity LED
and a fire simulating yellow and red LED together or
separate as Button LED
with a code involving 'random'.
The heart beat, I have at least managed to get 'blink' to work
again inside of the code. But the 'fade' example suits the
heart beat better- didn't get that working yet.
And of course, all of them still employ 'delay' again.
Here's the fire effect one, that only lights the LED up
straight and then stronger and that's it- no fire effect.

// LED Fire Effect with one LED

const int ButtonLed = 9;


void setup()
{
  pinMode(ButtonLed, OUTPUT);

}

void loop() {
  analogWrite(ButtonLed, random(1000)+1305);
  delay(random(100));
}