ArduCopter

A hobby UAV project.

Ein Kommentar

  1. THANKS Sebastian, I have used your library to control my Sony NEX5 camera from a 1-2mS standard Radio Control receiver servo output channel. Starts continuous still photo taking with variable time interval, selected by a push-button and/or starts and stops the video recording……

    //SONY NEX INFRARED CAMERA CONTROL USING ARDUINO

    #include // this is the camera IR code library http://sebastian.setz.name/arduino/my-libraries/multi-camera-ir-control/
    Sony A900(9); // camera control Infrared LED on Arduino pin PWM 9

    #define RX_SIGNAL_IN_INTERRUPT 0 // this times the R/C control signal input
    #define RX_SIGNAL_IN_PIN 2 // Arduino pin Digital 2
    #define IR_LED 0 // IR LED on pin PWM 9
    #define BUTTON_CHANGE_INTERVAL 5 // push button PWM pin 5 should tie BUTTON_CHANGE_INTERVAL to ground
    #define DEBOUNCE_INTERVAL 50
    #define DEFAULT_PHOTO_INTERVAL 2000 // default two seconds delay between photos
    #define MAX_PHOTO_INTERVAL 20000 // Twenty seconds maximum time between photos
    #define NEUTRAL_RX 1500 // receiver output signal with Tx stick/control centered 1500uS

    volatile int nRXIn = NEUTRAL_RX;
    volatile unsigned long ulStartPeriod = 0; // measures Rx pulse width
    volatile boolean bNewRXSignal = false;

    void setup() {
    pinMode(RX_SIGNAL_IN_PIN,INPUT); // defines pins
    pinMode (IR_LED,OUTPUT);
    attachInterrupt(RX_SIGNAL_IN_INTERRUPT,calcInput,CHANGE);
    pinMode(BUTTON_CHANGE_INTERVAL, INPUT);
    digitalWrite(BUTTON_CHANGE_INTERVAL, HIGH); // enable internal pullup
    }

    void loop()
    {
    //**************start of timer insert
    static uint32_t photo_interval = DEFAULT_PHOTO_INTERVAL;

    if (!digitalRead(BUTTON_CHANGE_INTERVAL)) { // button should tie BUTTON_CHANGE_INTERVAL to ground
    delay(DEBOUNCE_INTERVAL); // button debounce
    photo_interval += 2000; // add two seconds each button press
    if (photo_interval > MAX_PHOTO_INTERVAL) {
    photo_interval = DEFAULT_PHOTO_INTERVAL; // reset timer interval to default 2 seconds
    }
    while (!digitalRead(BUTTON_CHANGE_INTERVAL)){ // wait for button to be released
    }
    delay(DEBOUNCE_INTERVAL); // button debounce
    }
    //************end of timer insert
    //if(bNewRXSignal)
    {

    if(nRXIn >1800) // receiver signal more than 1800uS pulse width
    {
    A900.shutterNow(); // take one still photo
    delay(photo_interval); // time in mS between still photos

    }

    if(nRXIn <1200) // receiver signal less than 1200uS pulse width
    {
    A900.toggleVideo(); // Start video recording, RC control to neutral (1500 uS) before 8 seconds for continuous video recording
    delay(8000); // toggle RC control again to stop video recording

    }

    if(bNewRXSignal)

    bNewRXSignal = false;
    }

    }
    void calcInput()
    {

    if(digitalRead(RX_SIGNAL_IN_PIN) == HIGH) // timing Rx pulse width
    {

    ulStartPeriod = micros();
    }
    else
    {

    if(ulStartPeriod && (bNewRXSignal == false))
    {
    nRXIn = (int)(micros() – ulStartPeriod); //timing Rx pulse width
    ulStartPeriod = 0;

    bNewRXSignal = true;

    }
    }
    }

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind markiert *