Skip to content

Instantly share code, notes, and snippets.

@daniel-j
Last active August 29, 2015 14:10
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 daniel-j/4ec9dd6f10fa287b55ed to your computer and use it in GitHub Desktop.
Save daniel-j/4ec9dd6f10fa287b55ed to your computer and use it in GitHub Desktop.
Take a photo with a system camera using a button connected to GPIO!
trigger-camera
#!/bin/bash
gcc -o trigger-camera main.c -lwiringPi
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <wiringPi.h>
#define TRIGGER_PIN 9
void setup() {
if (wiringPiSetup () == -1) {
exit (1);
}
printf ("Setup... \n");
printf("Button pin: %d\n", TRIGGER_PIN);
pinMode(TRIGGER_PIN, INPUT);
}
void waitButton (void) {
printf ("Waiting for button press...\n");
while (digitalRead(TRIGGER_PIN) == HIGH) {
delay (50);
}
printf ("Button pressed!\n");
}
void takePhoto() {
printf("Taking photo...\n");
system("./takephoto.sh");
printf("Photo captured!\n");
}
int main (void) {
setup();
for(;;) {
waitButton();
//delay(1000);
takePhoto();
//delay(1000);
}
}
#!/bin/bash
#TIMESTAMP=$(date +"%m-%d-%Y")
DATE=`date +"%Y-%m-%d"`
TIME=`date +"%H-%M-%S"`
ROOT=/julfest/bilder
mkdir -p $ROOT/$DATE/
FILENAME="$ROOT/$DATE/julfest $DATE $TIME.jpg"
gphoto2 --auto-detect --capture-image --get-all-files --filename="$FILENAME"
chown djazz:users "$FILENAME"
[Unit]
Description=Trigger Camera Service
Requires=network.target local-fs.target
[Service]
Type=forking
KillMode=none
ExecStart=/usr/bin/tmux new-session -d -P -s trigger-camera -n trigger-camera ./trigger-camera
ExecStop=/usr/bin/tmux send-keys -t trigger-camera:trigger-camera C-c
WorkingDirectory=/path/to/trigger-camera/
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment