Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaellehmkuhl/0c8e12e128bd32175e8c892cf80884c6 to your computer and use it in GitHub Desktop.
Save rafaellehmkuhl/0c8e12e128bd32175e8c892cf80884c6 to your computer and use it in GitHub Desktop.
#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();
}
@rafaellehmkuhl
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment