-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathakilli-sapka.ino
70 lines (57 loc) · 1.62 KB
/
akilli-sapka.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
* Elbistan Proje IHL, 2021
* TUBITAK 4006 Proje Ekibi
*
* Ramazan Emre Osmanoglu, Duha Emre Coskun, Yunus Emre Cimentor, Recep Tanriverdi
*
* This project is licensed under GPL 3.0, see LICENSE for more information.
*/
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#define BUZZER_1 8
#define BUZZER_2 7
#define MEASURE_DELAY 1000
#define BEEP_DELAY 2000
const int X_LIMIT = 4;
const int Y_LIMIT = 4;
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified();
void setup(void)
{
pinMode(BUZZER_1, OUTPUT);
pinMode(BUZZER_2, OUTPUT);
Serial.begin(9600);
if(!accel.begin())
{
Serial.println("ADXL345 tanimlanamadi.");
while(1);
}
}
void beep_buzzers() {
digitalWrite(BUZZER_1, HIGH);
digitalWrite(BUZZER_2, HIGH);
delay(BEEP_DELAY);
digitalWrite(BUZZER_1, LOW);
digitalWrite(BUZZER_2, LOW);
}
boolean is_tilting = false;
void loop(void)
{
sensors_event_t event;
accel.getEvent(&event);
Serial.print("X: "); Serial.print(event.acceleration.x); Serial.print(" ");
Serial.print("Y: "); Serial.print(event.acceleration.y); Serial.print(" ");
Serial.println("");
if((event.acceleration.x >= X_LIMIT || event.acceleration.x <= -X_LIMIT) || (event.acceleration.y >= Y_LIMIT || event.acceleration.y <= -Y_LIMIT)) {
if(is_tilting == true) {
beep_buzzers();
is_tilting = false;
} else {
Serial.println("TILT DETECTED, WAITING...");
is_tilting = true; // Set tilting true
}
} else {
is_tilting = false;
}
delay(MEASURE_DELAY);
}