-
Notifications
You must be signed in to change notification settings - Fork 0
/
CareBike.ino
204 lines (138 loc) · 2.48 KB
/
CareBike.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//Created By Refael Ivgi
#include <SoftwareSerial.h>;
#include <TinyGPS++.h > ;
static const int RXPin = 6, TXPin = 10;
float LAT,LON;
int SEND_TWICE=0,DILUG;
int POWER_KEY_GSM=9;
int SMS_ONCES=0;
TinyGPSPlus gps;
SoftwareSerial mySerial(7, 8);
SoftwareSerial ss(RXPin , TXPin);
void setup()
{
mySerial.begin(19200); // For GSM
ss.begin(9600); //For GPS
Serial.begin(9600);
//check for PIN 9 Before Start
if (digitalRead(POWER_KEY_GSM) == LOW)
{
pinMode(9, OUTPUT);
digitalWrite(9,HIGH);
}
}
///פונקציית שליחת הודעה עם המיקום ///
void SHLIHAT_MIKUM()
{
if (SMS_ONCES==1)
{
mySerial.print("\r");
delay(100);
mySerial.print("AT+CMGF=1\r");
delay(100);
mySerial.print("AT+CMGS=\"+972XXXXXXX\"\r"); // insert Phone number
delay(100);
mySerial.print("WARNING FROM CareBike");
mySerial.println("");
mySerial.print("https://www.google.co.il/maps/@");
mySerial.print(LAT);
mySerial.print(",");
mySerial.print(LON)
mySerial.print(",19z?hl=iw\r");
smartDelay(1000);
mySerial.write(0x1A);
delay(1000);
}
;++ SMS_ONCES
}
static void oreh(float mikum , bool valid)
{
if(SEND_TWICE<=2)
{
if (!valid)
{
while (DILUG-- > 1)
Serial.print('*');
Serial.println('');
}
else
{
Serial.println(mikum);
LAT=mikum;
SEND_TWICE++;
}
}
התאמת זמנים // ;
smartDelay(0);
}
static void rohav(float mikum , bool valid)
{
if(SEND_TWICE<=2)
{
if (!valid)
{
while (DILUG-- >1)
Serial.print('*');
Serial.println('');
}
else
{
LON=mikum;
Serial.println(mikum);
SEND_TWICE++;
}
}
smartDelay(0);
}
void loop()
{
Initialization();
digitalWrite(9,HIGH);
delay(200);
int checkFlag = 0;
int DELAY_SHLIHA;
int s1=2;
int s2 =3;
pinMode(s1, INPUT);
pinMode(s2, INPUT);
Serial.println(s1);
if ( digitalRead(s1) == LOW || digitalRead(s2) ==LOW)
{
SMS_ONCES=0;
}
if (digitalRead(s1) == HIGH || digitalRead(s2) == HIGH)
{
while ((DELAY_SHLIHA<1200) && (digitalRead(s1) == HIGH || digitalRead(s2) == HIGH))
{
DELAY_SHLIHA++;
}
DELAY_SHLIHA=0;
if(digitalRead(s1) == HIGH || digitalRead(s2) == HIGH)
{
oreh(gps.location.lat(), gps.location.isValid());
rohav(gps.location.lng(), gps.location.isValid());
SEND_TWICE++;
checkFlag = 1;
if (checkFlag == 1)
{
if(SMS_ONCES<=1)
SHLIHAT_MIKUM();
}
}
}
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (ss.available)
gps.encode(ss.read());
}
while (millis() - start < ms);
}
void initialization()
{
oreh(gps.location.lat(), gps.location.isValid());
rohav(gps.location.lng(), gps.location.isValid());
}