Data transmission using LED using buttons

Hi

I am trying to build a data transmission system using an LED. I have plugged in two buttons to the arduino to decide the data to be transmitted ( 00/01/10/11 ). This part of the code is working which I tested using LEDs connected to the arduino. Now, I want to transmit this two bit binary code over a LED such that a photodiode connected to another arduino can read it and perform an action. I have put in my code I have for the two buttons to serial write to the laptop. How should I modify this code to transmit it over a LED? To clarify, I am not looking for the LED to come on and off but transmit the two bit binary data while it is on.

int switchPin1 = 8;
int switchPin2 = 9;
int ledPin1 = 13;
int ledPin2 = 12;
boolean lastButton1 = LOW;
boolean lastButton2 = LOW;
boolean ledOn1 = false;
boolean ledOn2 = false;
boolean currentButton1 = LOW;
boolean currentButton2 = LOW;

void setup()
{
  pinMode(switchPin1, INPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(switchPin2, INPUT);
  pinMode(ledPin2, OUTPUT);
  Serial.begin(9600);
}

boolean debounce1(boolean last1)
{
  boolean current1 = digitalRead(switchPin1);
  if(last1 != current1)
  {
    delay(5);
    current1 = digitalRead(switchPin1);
  }
  return current1;
}

boolean debounce2(boolean last2)
{
  boolean current2 = digitalRead(switchPin2);
  if(last2 != current2)
  {
    delay(5);
    current2 = digitalRead(switchPin2);
  }
  return current2;
}

void loop()
{
  currentButton1 = debounce1(lastButton1);
  currentButton2 = debounce2(lastButton2);
  if (lastButton1 == LOW && currentButton1 == HIGH)
  {
    ledOn1 = !ledOn1;
  }
  if (lastButton2 == LOW && currentButton2 == HIGH)
  {
    ledOn2 = !ledOn2;
  }
  lastButton1 = currentButton1;
  lastButton2 = currentButton2;
  digitalWrite(ledPin1, ledOn1);
  Serial.print(ledOn1);
  digitalWrite(ledPin2, ledOn2);
  Serial.println(ledOn2);
}

I am not looking for the LED to come on and off but transmit the two bit binary data while it is on.

If you are sending a 0, the LED is off for a period of time. If you are transmitting a 1, the LED is on for a period of time. That period of time defines the bit rate. You also need a way for each side of the communications link to know when that period of time starts and ends.

You can not transmit data with the LED on all the time.

I am aware of that. My mistake I didn't phrase it correctly. I need the bit rate to be high enough so as to make the flickering LED 'seem' as 'constantly on'.

The problem is, if I keep one button pressed and the other unpressed I need the LED to toggle on and off (at a high rate) and not one LED stays on and the other off. Also, if I require this LED to be read by a photodiode at a distance of say 3-4 feet, how do I set up the arduino to give me an input (oo/01/10/11) for a transmitter circuit?

I need the bit rate to be high enough so as to make the flickering LED 'seem' as 'constantly on'.

The rate at which you can receive data depends on how fast the receiver (unidentified) can react to a change in light level.

To send a 1, you have o1o. The send a 0, you have ooo. Since you are sending 00, 01, 10, or 11, you will have oooooo, oooo1o, o1oooo, or o1oo1o. I can't imagine that with that low a on time, that the light will appear as ON all the time. If you invert the signal, you'd have 111111, 1111o1, 1o1111, or 1o11o1. More likely to appear on all the time, but may be more difficult for the receiver to deal with.

The receiver would be easier to deal with me for me. It will be a photo-receiver.

How would I go about if I just want the data (00/01/10/11) to be output from the arduino and an input to a transmitter circuit?

Thank you for your help. I'm gaining a lot of clarity in my head.

It will be a photo-receiver.

But, what kind is it? There are different kinds of photo receivers. Some are fast; most are not.

How would I go about if I just want the data (00/01/10/11) to be output from the arduino

You simply turn the LED off for a period of time, and then back on, to send a 1, and off for a longer period of time to send a 0.

You will have to deal with the issue of synchronization, though. The receiver has to know when you are beginning to send data, so it recognizes when the three bit value is to be/has been sent.