Created
May 12, 2017 01:48
-
-
Save rafaellehmkuhl/0c8e12e128bd32175e8c892cf80884c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Average.h> | |
// Camera delay meter | |
int shutterPin = 13; // RTK trigger signal on pin 13 | |
int pixhawkPin = 5; // Pixhawk trigger signal on pin 5 | |
bool pixhawkOn = HIGH; | |
bool triggerState = LOW; // Current trigger state | |
bool isShoting = LOW; // Current trigger state | |
long triggerTimeOn = 0; // Time when the trigger starts | |
long triggerTimeOff = 0; // Time when the trigger stops | |
long currentTime = 0; // Current Time | |
long triggerStartCount = 0; | |
float timeOn = 0; | |
float delayAmostragem = 0; | |
Average<float> ldrAverage(100); | |
void setup() { | |
// Initialize the trigger pin as an OUTPUT: | |
pinMode(shutterPin, OUTPUT); | |
// Initialize the pixhawk pin as an INPUT: | |
pinMode(pixhawkPin, INPUT); | |
// Initialize serial communication: | |
Serial.begin(250000); //Inicia a comunicação serial | |
} | |
void loop() { | |
currentTime = millis(); | |
pixhawkOn = digitalRead(pixhawkPin); | |
if (pixhawkOn == LOW){ | |
if (triggerState == LOW){ | |
if (millis() - triggerStartCount > 1750){ | |
triggerState = HIGH; | |
triggerStartCount = millis(); | |
} | |
} | |
} | |
if ((millis() - triggerStartCount) > 90){ | |
if (triggerState == HIGH){ | |
digitalWrite(shutterPin, HIGH); | |
isShoting = HIGH; | |
triggerState = LOW; | |
} | |
} | |
if (millis() - triggerStartCount > 590){ | |
if (isShoting == HIGH){ | |
digitalWrite(shutterPin, LOW); | |
isShoting = LOW; | |
} | |
} | |
Serial.print("Pixhawk state: "); | |
Serial.print(pixhawkOn); | |
Serial.print(" // "); | |
Serial.print("Shot state: "); | |
Serial.print(isShoting); | |
Serial.print(" // "); | |
//Serial.print("Trigger Start Count: "); | |
//Serial.print(triggerStartCount); | |
//Serial.print(" // "); | |
//Serial.print("Trigger Time On: "); | |
//Serial.print(triggerTimeOn); | |
//Serial.print(" // "); | |
//Serial.print("Trigger Time Off: "); | |
//Serial.print(triggerTimeOff); | |
//Serial.print(" // "); | |
Serial.print("Current time: "); | |
Serial.println(currentTime); | |
delayAmostragem = (micros() - timeOn)/1000000; | |
timeOn = micros(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@patrickelectric