-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeftbox.cpp
More file actions
131 lines (96 loc) · 2.93 KB
/
theftbox.cpp
File metadata and controls
131 lines (96 loc) · 2.93 KB
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
#include "thingProperties.h"
#include <iostream>
#include <string>
#include <fstream>
//#include <windows>
using namespace std;
int const trigPin = D5;
int const echoPin = D6;
int const buzzPin = D4;
string link;
void setup() {
pinMode(trigPin, OUTPUT); // trig pin will have pulses output
pinMode(echoPin, INPUT); // echo pin should be input to get pulse width
pinMode(buzzPin, OUTPUT);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
// Your code here
int duration, distance;
// Output pulse with 1ms width on trigPin
digitalWrite(trigPin, HIGH);
delay(1);
digitalWrite(trigPin, LOW);
// Measure the pulse input in echo pin
duration = pulseIn(echoPin, HIGH);
// Distance is half the duration devided by 29.1 (from datasheet)
distance = (duration/2) / 29.1;
// if distance less than 0.3 meter and more than 0 (0 or less means over range)
if (distance <= 30 && distance >= 10) {
// Buzz
digitalWrite(buzzPin, HIGH);
t=1;
} else {
// Don't buzz
digitalWrite(buzzPin, LOW);
t=0;
}
// Waiting 60 ms won't hurt any one
delay(6);
}
/*
Since Led is READ_WRITE variable, onLedChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLedChange() {
// Add your code here to act upon Led change
Serial.println(led);
/*
if (led) {
digitalWrite(ledl, HIGH);
Serial.println("ON");
link="https://maker.ifttt.com/trigger/true/with/key/hleiEMS-SlcwEJ24woQ-4ZQZiN2TKDfufRrIKSF9Iwj";
system(link.c_str());
string url="https://maker.ifttt.com/trigger/true/with/key/hleiEMS-SlcwEJ24woQ-4ZQZiN2TKDfufRrIKSF9Iwj";
fstream fs;
fs.open(url);
fs.close();
//ShellExecute(NULL, "open", "http://www.yahoo.com/",NULL, NULL, SW_SHOWNORMAL);
}
else {
digitalWrite(ledl, LOW);
Serial.println("OFF");
}
*/
}
/*
Since L is READ_WRITE variable, onLChange() is
executed every time a new value is received from IoT Cloud.
*/
void onLChange() {
// Add your code here to act upon L change
}
/*
Since T is READ_WRITE variable, onTChange() is
executed every time a new value is received from IoT Cloud.
*/
void onTChange() {
// Add your code here to act upon T change
}