-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTeensyduino_Code.c
77 lines (52 loc) · 1.56 KB
/
Teensyduino_Code.c
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
71
72
73
74
75
76
77
//Constants:
#include <SoftwareSerial.h>
SoftwareSerial BTserial(0, 1); // RX | TX
// For BNO055 Adafruit
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#define BNO055_SAMPLERATE_DELAY_MS (100)
Adafruit_BNO055 bno = Adafruit_BNO055(55);
const int flexPin = 34; //pin A0 to read analog input
int value; //save analog value
void setup(){
Serial.begin(115200);
Serial.println("Arduino is ready");
BTserial.begin(9600); // HC-05 default serial speed for commincation mode is 9600
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}
delay(1000);
bno.setExtCrystalUse(true);
}
void loop(){
value = analogRead(flexPin); // Read and save analog value from potentiometer
if(value>950)
{
delay(1000);
Serial.print("Flex Sensor : ");
Serial.println("Drink water\n");
BTserial.write("Drink water");
delay(1000);
}
sensors_event_t event;
bno.getEvent(&event);
//event.orientation.y = -10;
//Serial.print("y: ");
Serial.println(event.orientation.y, 4);
delay(1000);
if(event.orientation.y < -10)
{
delay(1000);
Serial.print("Accelerometer : ");
Serial.print("Help Me!!\n ");
BTserial.write("Help Me!!");
delay(1000);
}
value = map(value, 700, 900, 0, 255); //Map value 0-1023 to 0-255 (PWM)
delay(BNO055_SAMPLERATE_DELAY_MS);
}