/* Arduino Fiber Optics Example Code * Copyright 2010 SparkFun Electronics * Written by Hilary Hoops * This code is example code for receiving a fiber optic signal at over 0.1Mbps * The digital input pin begins when it notices a change on the line (interrupt driven) * Then the controller reads in the data quickly then decodes it into its bi-phase form * then decodes it again into its binary form, finally printing out the received * character to the hardware serial port */ const int in = 4; // Fiber Optic Rx pin const int rawsize=500; // Raw Data Size const int BPDsize=150; // Decoded Biphase Size const int BDsize=150; // Binary Data Size int RawData[rawsize]; // Raw Data int BPdata[BPDsize]; // Biphase data int Bdata[BDsize]; // Binary data char mychar; // Character Read void setup() { //Begin serial port for reporting character recieved Serial.begin(9600); //Set input pin to input pinMode(in,INPUT); //Start reading the data when a change happens on pin 3 (connect input pin and pin 3 together) attachInterrupt(1, my_interrupt_handler, CHANGE); } void loop(){ } void my_interrupt_handler() // This is essentially a "debounce" for the interrupt { static unsigned long last_interrupt_time = 0; unsigned long interrupt_time = millis(); // If interrupts come faster than 200ms, assume it's a bounce and ignore if (interrupt_time - last_interrupt_time > 200) { FiberRead(); } last_interrupt_time = interrupt_time; } void FiberRead() { //Collect all raw data coming in for(int i=0;i>4; } //Raw data is read faster than it is transmitted, so we correct for timing and noise int k=0; int q=0; for(int j=0;j=9){ q++; BPdata[q]=RawData[j]; } q++; k=0; } } //Decode the Biphase data into Binary int m=0; int j=0; while(BPdata[m]!=BPdata[m+1]) m++; for(m; m