-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
45 lines (35 loc) · 831 Bytes
/
Copy pathmain.cpp
File metadata and controls
45 lines (35 loc) · 831 Bytes
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
#include <Arduino.h>
#include <Wire.h>
#include <MPU6050.h>
#include <BluetoothSerial.h>
#define LED 2
BluetoothSerial BT;
MPU6050 mpu;
float prevAx = 0;
int thresh = 8;
int count = 0;
void setup() {
Serial.begin(115200);
Wire.begin(21, 22);
mpu.initialize();
pinMode(LED, OUTPUT);
BT.begin("ESP32-MPU");
Serial.println("Bluetooth started, pair with ESP32-MPU");
}
void loop() {
int16_t ax, ay, az, gx, gy, gz;
mpu.getAcceleration(&ax, &ay, &az);
mpu.getRotation(&gx, &gy, &gz);
float Ax = ax / 16384.0f * 9.81f;
Serial.println(Ax);
if ((Ax - prevAx) > thresh) {
digitalWrite(LED, HIGH);
count+=1;
BT.print("SCROLL DETECTED: ");
BT.println(count);
delay(500);
digitalWrite(LED, LOW);
}
prevAx = Ax;
delay(50);
}