BinHong Lee преди 7 години
ревизия
dd4d880e00
променени са 3 файла, в които са добавени 107 реда и са изтрити 0 реда
  1. +3
    -0
      .gitignore
  2. +2
    -0
      compileandexecute.sh
  3. +102
    -0
      main.c

+ 3
- 0
.gitignore Целия файл

@@ -0,0 +1,3 @@
*.o
photo.jpg
sendMail.sh

+ 2
- 0
compileandexecute.sh Целия файл

@@ -0,0 +1,2 @@
g++ main.c -o main.o -lwiringPi
./main.o

+ 102
- 0
main.c Целия файл

@@ -0,0 +1,102 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <wiringPi.h>
#include <wiringPiI2C.h>
#include <errno.h>

#define MPU3050_PWR (0x6b)
#define MPU3050_I2C (0x69)
#define MPU3050_REG (0x21)
#define LED 0
#define BUTTON 5
#define DEBOUNCE_MS 1000

volatile int trigger;
volatile uint8_t photoTaken;
volatile unsigned int prevTime = 0;
volatile uint8_t btnClicked = 0;

void myInterrupt(void)
{
unsigned int currentTime = millis();
unsigned int deltaTime = currentTime - prevTime;

printf("%d\n", deltaTime);
if (deltaTime > DEBOUNCE_MS)
{
btnClicked = 1;
prevTime = currentTime;
printf("test\n");
if (trigger == 0)
{
photoTaken = 0;
trigger = 1;
digitalWrite(LED, LOW);
printf("T R I G G E R R E D\n");
}
else
{
photoTaken = 0;
trigger = 0;
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
delay(100);
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
printf("T R I G G E R R E D A G A I N\n");
}
}
}

int main()
{
photoTaken = 0;
trigger = 0;

wiringPiSetup();
pinMode(BUTTON, INPUT);
pinMode(LED, OUTPUT);
int isrSetup = wiringPiISR(BUTTON, INT_EDGE_FALLING, &myInterrupt);
int i2cSetup = wiringPiI2CSetup(MPU3050_I2C);

if (i2cSetup < 0||isrSetup < 0)
return 0;

wiringPiI2CWriteReg8(i2cSetup, MPU3050_PWR, 0x01);
int gyroInput;
int count = 0;
while(1)
{
gyroInput = wiringPiI2CReadReg8(i2cSetup, MPU3050_REG);

if(gyroInput == 0)
{
count++;
if (count > 10 && trigger == 0 && photoTaken == 0)
{
digitalWrite(LED, HIGH);
delay(2000);

if (!btnClicked)
{
system("raspistill -v -o photo.jpg && ./sendMail.sh");
photoTaken = 1;
}

btnClicked = 0;
}
}
else
{
count = 0;
digitalWrite(LED, LOW);
}

delay(100);
}
return 0;
}

Зареждане…
Отказ
Запис