Reading IR-data from Arduino with Adobe Flash

Hello all,

I recently started tinkering with Arduino for my graduation project. As for that, this is my first post here and I hope someone can help me out with a problem I'm beating my head around for. My wish is to send infrared signals received by my Arduino Uno into Adobe Flash (AS3) so I can make my AS application interpret them and respond to it. To set up communication between Flash and Arduino I've used a standard Firmata sketch in combination with serproxy as explained here Arduino Flash communication AS3 - Firmata ⋆ Kasper Kamperman. This example works beautifully.

It is possible to monitor sensor activity and call upon pin values, however a problem arises when trying to 'continuously' read (using a timer function with few millisecond interval) a digital pin to register the IR signals being recieved by the Arduino. Somehow the pin states retrieved by flash (Being either HIGH(1) or LOW(0)) do not match the signal actually being send. A part of the AS3 script i'm using

var refreshTimer = new Timer(10); // reads data every 10 ms

refreshTimer.addEventListener(TimerEvent.TIMER, onTick);

function onTick(event:TimerEvent):void{
	var detectorValue = a.getDigitalData(2);
	trace(detectorValue);
}

The InfraRed signal I am sending comes from another battery powered arduino with an IR LED attached to it. The sketch beneath is running on it. I only send the binairy 1 data as a 38 kHz signal that can be read by the reciever.

/*SENDER
----------*/
int ir_pin = 10;                         //Sensor pin 1 wired through a 220 ohm resistor
int led_pin = 13;                           //"Ready to Receive" flag, not needed but nice
int bin_1 = 22;                           //Binary 1 threshold (Microseconds)
int pauze = 100;                             //Binary 0 threshold (Microseconds)
int dataOut = 0;


void setup() {
  pinMode(led_pin, OUTPUT);             //This shows when we're ready to recieve
  pinMode(ir_pin, OUTPUT);
  digitalWrite(led_pin, LOW);       //not ready yet
  digitalWrite(ir_pin, LOW);        //not ready yet
  Serial.begin(9600);
}

void loop() {
    int numbertoSend = 1;
    dataOut = numbertoSend ;
    int key = 0;
    key = sendIRKey(dataOut);             //Fetch the key
    }
    
int sendIRKey(int dataOut) {
  int data[4];
  for (int i=0; i<4; i++) {
    data[i] = dataOut>>i & B1;   //encode data as '1' or '0'
    }   
  for (int i=0; i<4; i++) {
    if (data[i] == 1){
      digitalWrite(led_pin, HIGH); //Ok, i'm going to send now
      oscillationWrite(ir_pin, bin_1); // the IR LED on ir_pin send a signal for bin_1 time on 38khz oscillation
      Serial.print("1");
    }
    else{   
      digitalWrite(led_pin, LOW); // not sending anything now  
      delay(bin_1); // does not send a signal for bin_1 time
      Serial.print("0");
    }
  }
  digitalWrite(ir_pin, HIGH);
  digitalWrite(led_pin, LOW);
  delay(pauze); // delay after send
  return dataOut;                            //Return key number
}

// this will write an oscillation at 38KHz for a certain time in milliseconds
void oscillationWrite(int pin, int time) {
  for(int i = 0; i <=(time*1000)/26; i++) {
    digitalWrite(pin, HIGH);
    delayMicroseconds(13);
    digitalWrite(pin, LOW);
    delayMicroseconds(13);
  }
}

I've been play around a lot with refresh rate in Flash and with the signal send through arduino, but it just cannot get the reading to match. It should not be the problem of the signal itself since i'm able to register and decode binairy signals with an arduino sketch other then firmata perfectly (a matching sender and reciever are described by David Cuartielles here --> http://forum.arduino.cc/index.php/topic,17965.0.html).

Can anyone help my with how to read this data through Firmata in adobe Flash or with a method to send a value/string from an arduino receiver sketch to flash in another way? Your help would be most welcome!

As its for your exam credits (?), the best approach may be to point you in the right direction to where you can find the information on Aduino & IR.

There are 2 excellent resources on IR & Arduino.

Search for IRremote library - Ken Shirrif (you should be able to see how they do it and then figure the rest out for your own project)
and also sb-projects the 'oracle' for all you want to know about IR
There is also another Arduino IR library called IRLib

Unfortunatley, I haven't used firmata and can't help there, but maybe I should try it. The Arduino libraries simply send the decoded IR out over serial.