james kain / Mbed 2 deprecated test_shutter

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002  
00003 //are these actually used ??? - not used sg. Was for the inital LED's you had. Then I thought of the 4 into 16 while coding
00004 DigitalOut ext_led[8] = {p21,p22,p23,p24,p25,p26,p27,p28};
00005 //DigitalOut int_led[4] = {LED1, LED2, LED3, LED4};
00006 
00007 // from handbook for BusOut:  Flexible way to write multiple DigitalOut pins as one value
00008 BusOut int_led(LED1, LED2, LED3, LED4);  //four built-in LEDs used to display the counter from the trigger
00009  
00010 //original from Sam in Seaside
00011 //DigitalInOut fire(p20);     //connected to the tip of 2.5mm connector (T2i)
00012 //DigitalInOut pre_fire(p19); //connected to the mid-connection for 2.5mm connector (T2i)
00013 
00014 //modification to connect to the IMU carrier board
00015 DigitalInOut fire(p29);     //connected to the tip of 2.5mm connector (T2i)
00016 DigitalInOut pre_fire(p30); //connected to the mid-connection for 2.5mm connector (T2i)
00017 
00018 // using ADIS hardware
00019 //DigitalInOut fire(p29);     //connected to the tip of 2.5mm connector (T2i)
00020 //DigitalInOut pre_fire(p30); //connected to the mid-connection for 2.5mm connector (T2i)
00021 
00022 InterruptIn x(p18); 
00023 Serial pc(USBTX, USBRX);
00024 
00025 
00026 #define US_INTERVAL 500
00027     
00028 //set the resolution of the timing information
00029 #define MS_INTERVAL 2   //interval used to change the counter display 
00030  
00031 void resetLed()
00032 {
00033     for(int i=0; i<8; i++)
00034     {
00035         ext_led[i] = 0;
00036     }
00037     int_led = 0;
00038 }
00039 
00040 //xFire procedure is not used in the logic in main. This was to test the accuracy of the hotshoe trigger and it was spot on sg
00041 void xFire()
00042 {
00043     for(int i=1; i<16; i++)
00044     {
00045         wait_us(US_INTERVAL);
00046         int_led = i;
00047     }
00048     return;
00049 }
00050 
00051 volatile bool trigger = 0;
00052 Ticker trig;
00053 void setTrig()
00054 {
00055     trigger = 1;
00056 }
00057  
00058 int main()
00059 {
00060     // try open drain driving (internal pullup in camera?)
00061     //x procedure not used below 
00062     x.mode(PullUp);
00063     x.fall(&xFire);   
00064     
00065     fire.output();  //set the fire pin as outoput
00066     pre_fire.output();  //set the pre-fire pin as output
00067     //fire.mode(OpenDrain);
00068     
00069     //set up for the first trigger
00070     fire = 1;
00071     pre_fire = 1;
00072     
00073     // reset the LED's
00074     resetLed();
00075     
00076     //trig is a ticker used to repeatedly fire a trigger at the interval (e.g., 7.5 secs)
00077     trig.attach(&setTrig, 7.5f);  //set ticker interval to 7.5secs
00078     
00079     // start the program
00080     while(1)
00081     {
00082 //        if(pc.readable())  //used to trigger from a keyboard click
00083 //        {
00084 //            char ch = pc.getc();  //read the keyboard click
00085 
00086           //below used for repeatedly triggering on a ticker
00087           if(trigger)  //is the ticker has fired the trigger, proceed ...
00088           {
00089             trigger = 0;  //reset the trigger to zero
00090             
00091             // turn all leds off to start the counter
00092             resetLed();
00093             
00094             // pre-fire the trigger using the mid-body 2.5mm connection (T2i)
00095             pre_fire = 0;
00096             
00097             wait(.25f);  //wait for 0.25 secs
00098             
00099             fire = 0; //fire the trigger using the tip connection
00100             
00101             wait(0.100f); // empirically known delay to get us to the range of the 4 timing LEDs 
00102             
00103             // maybe we need more or later just use these...
00104             //just count up to 16 diaplaying the results on the LEDs
00105             for(int i=1; i<16; i++)
00106             {
00107                 wait_ms(MS_INTERVAL);
00108                 int_led = i;  //write to the BusOut to display the counter on 4 LEDs
00109             }
00110             
00111             //reset for the next trigger
00112             // release the trigger
00113             fire = 1;
00114             pre_fire = 1;
00115         }
00116     }
00117 }