-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproje.ino
107 lines (88 loc) · 2.43 KB
/
proje.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
/*
*
*
* Projenin Verici Kodları Burada Yer Almaktadır.
* Bu Proje Gomulu Sistemler Dersi icin Hazirlanmistir.
* Son Degistirilme Zamani: 30.05.2023
*
*/
#include <SD.h>
#include "getTemperatures.h"
#include "calcSpeed.h"
#include "Lora.h"
#define HALL_EFFECT_PIN 3
#define SD_CS 8
int sdFileCount = 0;
String sdFileName = "";
SdFile root;
uint32_t time = 0;
void setup() {
Serial.begin(9600); // bilgisisayar ile haberleşme
//SDCARD ADD TITLE
Serial.println("SD kart baslatiliyor...");
if (!SD.begin(SD_CS)) {
Serial.println("SD karta baglanilamadi!");
} else {
Serial.println("SD karta baglanildi.");
File root = SD.open("/");
while (true) {
File saveFile = root.openNextFile();
if (!saveFile) {
break;
}
String fileName = saveFile.name();
if (fileName.startsWith("DATAS_") && fileName.endsWith(".TXT")) {
int num = fileName.substring(6, fileName.length() - 4).toInt();
if (num >= sdFileCount) {
sdFileCount = num + 1;
}
}
saveFile.close();
}
root.close();
sdFileName = "DATAS_" + String(sdFileCount) + ".TXT";
File file = SD.open(sdFileName, FILE_WRITE);
if (!file)
Serial.println("dosyaya baglanilamadi");
file.println("zaman_ms ; hiz_kmh ; sicaklik1");
file.close();
}
sensors.begin();
//LORA INITIALIZE
pinMode(M0, OUTPUT);
pinMode(M1, OUTPUT);
LoRa.begin();
LoraE22Ayarlar();
digitalWrite(M0, LOW); //0
digitalWrite(M1, LOW); //0
// HALL INITIALIZE
pinMode(HALL_EFFECT_PIN, INPUT_PULLUP);
Timer1.initialize(); // kesme varsayılan olarak 1 saniye sayar
Timer1.attachInterrupt(speedCal); // bu fonksiyon taşmadan sonra çağrılır
attachInterrupt(digitalPinToInterrupt(HALL_EFFECT_PIN), speedInc, RISING); // hall effect yükselen kenarsa
//HALL END
}
void saveSDCard() {
File file = SD.open(sdFileName, FILE_WRITE);
time = millis(); //çalışmaya başladığından bir itibar o anki milisaniye
if (!file) {
Serial.println("Dosya acilamadi!");
} else {
file.print(time);
file.print(", ");
file.print(speed);
file.print(", ");
file.print(temp1);
file.print("\n");
file.close();
}
}
void loop() {
getTemps(); // Sicakliklar
Serial.print("Hiz: ");
Serial.print(speed);
Serial.println();
sendLora();
saveSDCard();
delay(100);
}