-
Notifications
You must be signed in to change notification settings - Fork 0
/
source_code.ino
48 lines (42 loc) · 1.02 KB
/
source_code.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
#include<FS.h>
String x;
int i;
int IRSensor =13; // connect ir sensor to arduino pin d7
int val=0;
void setup() {
Serial.begin(115200);
pinMode(IRSensor, INPUT);
Serial.println("begin sensor");
Serial.println("type print to see result");
bool success=SPIFFS.begin();
if(!success) {
Serial.println("error mounting file");
return;
}
}
void loop() {
val=digitalRead(IRSensor);
if(val==LOW)
{
delay(1000);
i++;
File file=SPIFFS.open("/sensor_dat.txt","w");
int bytesWritten=file.print(i);
file.close();
}
if(Serial.available()){
x = Serial.readStringUntil('\n');
if(x="print")
{
File file2=SPIFFS.open("/sensor_dat.txt","r");
if(!file2) {
Serial.println("failed to open file");
return;
}
Serial.println("content:");
while(file2.available()) {
Serial.write(file2.read());
}
file2.close();
}
}}