-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgyroscope.cpp
More file actions
37 lines (30 loc) · 979 Bytes
/
gyroscope.cpp
File metadata and controls
37 lines (30 loc) · 979 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
#include "gyroscope.h"
#include "socket.h"
#include <WiFi.h>
#include "actions.h"
extern ITG3200 gyro;
extern bool waiting_to_take_bottle;
extern WiFiClient client;
extern rgb_led_t rgb_led;
extern buzzer_t buzzer;
void setup_gyroscope(){
gyro.init();
gyro.zeroCalibrate(200, 10);
}
void take_bottle(){
char *bottle_taken_message = construct_bottle_taken_message();
// send the bottle_taken message
Serial.println("Sending bottle_taken message...");
client.write(bottle_taken_message);
waiting_to_take_bottle = false;
disable_led(rgb_led);
disable_buzzer(buzzer);
}
bool is_moving(){
float ax, ay, az;
gyro.getAngularVelocity(&ax, &ay, &az);
bool ax_condition = ax > ACCELERATION_THRESHOLD || ax < -ACCELERATION_THRESHOLD;
bool ay_condition = ay > ACCELERATION_THRESHOLD || ay < -ACCELERATION_THRESHOLD;
bool az_condition = az > ACCELERATION_THRESHOLD || az < -ACCELERATION_THRESHOLD;
return ax_condition || ay_condition || az_condition;
}