-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathFujishima.ino
160 lines (143 loc) · 3.13 KB
/
Fujishima.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#include "./SD.h"
#include "./Camera2.h"
#include "./BarometerThermohygrometer.h"
#include "./DCMotor.h"
#include "./IMU.h"
#include "./Light.h"
#include "./Servo.h"
#include "./GPS.h"
#include "./XBee.h"
#include "./Microphone.h"
Servo_t servo2;
uint16_t loop_count = 0;
int angle=0;//サーボモーターを回した角度
float lat;//緯度
float lng;//経度
int degree;//0~360で方角を表す
float height;
int SampleVolume=0;
int time=0;
void setup()
{
// Wire(Arduino-I2C)の初期化
Wire.begin();
// デバック用シリアル通信は9600bps
Serial.begin(9600);
SD_Init(); // これは絶対最初に初期化!
CAM2_Init(); // SDの後!
BTH_Init();
DCM_Init();
IMU_Init();
LIT_Init();
SRV_Init();
GPS_Init();
XBEE_Init();
MIC_Init();
Serial.println(F("Init done"));
delay(300);
}
void loop()
{
height=MjHeight();
if (height>10 && time>=1000){
time=0;
TakePicture();
}
if (height>25 && height<45){
MikeSample();
}else if(height<25 && height>3){
MikeRecord();
}
time+=20;
delay(20);
}
void MikeRecord(){
int volume=MIC_GetMaximum();
if(volume>SampleVolume){
sousin2();
Record2();
}}
void MikeSample(){
int tmp_volume=MIC_GetMaximum();
if (SampleVolume<tmp_volume){
SampleVolume=tmp_volume;
}
}
void TakePicture(){
CAM2_TakePic();
height=MjHeight();
Serial.print(F("Height = "));
Serial.print(height);
Serial.println(F(" [m]"));
lat=GPS_GetLat();//緯度を取得
lng=GPS_GetLng(); //経度を取得
degree=IMU_GetDeg();
sousin();
Record();
angle+=90;
if (angle==360){
angle=0;
}
if (angle!=270){
//SRV_SetPosition(angle);
servo2.position = angle;
} else if (angle==270){
//SRV_SetPosition(90);
servo2.position = 90;
}
//SRV_Run();
}
void sousin(){
XBEE_Print("rec_height:");
XBEE_Print(height);
XBEE_Print("rec_lat:");
XBEE_Print(lat);
XBEE_Print("rec_lng:");
XBEE_Print(lng);
XBEE_Print("rec_degree:");
XBEE_Print(degree);
XBEE_Print("rec_angle:");
XBEE_Print(angle);
}
void sousin2(){
XBEE_Print("voice!");
XBEE_Print("rec_height:");
XBEE_Print(height);
XBEE_Print("rec_lat:");
XBEE_Print(lat);
XBEE_Print("rec_lng:");
XBEE_Print(lng);
}
void Record(){
SD_Write("rec_height:");
SD_Write(String(height));
SD_Write("rec_lat:");
SD_Write(String(lat));
SD_Write("rec_lng:");
SD_Write(String(lng));
SD_Write("rec_degree:");
SD_Write(String(degree));
SD_Write("rec_angle:");
SD_Write(String(angle));
}
void Record2(){
SD_Write("voice!");
SD_Write("rec_height:");
SD_Write(String(height));
SD_Write("rec_lat:");
SD_Write(String(lat));
SD_Write("rec_lng:");
SD_Write(String(lng));
}
float MjHeight(){
// 高度計(気圧計)・温湿度計の値を更新
BTH_Update();
// // 高度計(気圧計)・温湿度計の値を表示
// BTH_Print();
float pressure = BTH_GetPressure();
// 気圧から高度に変換
// まあ,ざっくり 10m 上昇すると 1hPa 下がるとしようか.
float pressure_at_sea_level = 1013.250;
float height = (pressure_at_sea_level - pressure) * 10;
return height;
}