-
Notifications
You must be signed in to change notification settings - Fork 0
/
IOT-MicroLab.ino
108 lines (87 loc) · 2.51 KB
/
IOT-MicroLab.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
#include <SparkFun_APDS9960.h>
#include <dht.h>
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Wire.h>
#define APDS9960_INT 16 // Needs to be an interrupt pin D0
#define LED 0 // Led in NodeMCU at pin GPIO16 (D3).
#define FANP 14 // FAN in NodeMCU at pin GPIO14 (D5).
#define DHT11_PIN 15
char auth[] = "6TqHFVDYYPU6RL8lJ6xF-rQFst99JJat";
char ssid[] = "EartHTourisT";
char pass[] = "9200,27SunW";
// Global Variables
//Adafruit_APDS9960 apds;
dht DHT;
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
void handleGesture() {
if ( apds.isGestureAvailable() ) {
switch ( apds.readGesture() ) {
case DIR_UP:
Serial.println("UP");
digitalWrite(FANP, 0);
break;
case DIR_DOWN:
Serial.println("DOWN");
digitalWrite(FANP, 1);
break;
case DIR_LEFT:
Serial.println("LEFT");
digitalWrite(LED, HIGH);// turn the LED on.(Note that LOW is the voltage level but actually
break;
case DIR_RIGHT:
Serial.println("RIGHT");
digitalWrite(LED, LOW); // turn the LED off.
break;
case DIR_NEAR:
Serial.println("NEAR");
break;
case DIR_FAR:
Serial.println("FAR");
break;
default:
Serial.println("NONE");
}
}
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
pinMode(LED, OUTPUT); // LED pin as output.
pinMode(FANP, OUTPUT); // FAN pin as output.
pinMode(APDS9960_INT, INPUT);
// Initialize interrupt service routine
//attachInterrupt(0, interruptRoutine, FALLING);
digitalWrite(LED, 0);
digitalWrite(FANP, 0);
if ( apds.init() ) {
Serial.println(("APDS-9960 initialization complete"));
} else {
Serial.println(("Something went wrong during APDS-9960 init!"));
}
// Start running the APDS-9960 gesture sensor engine
if ( apds.enableGestureSensor(true) ) {
Serial.println(("Gesture sensor is now running"));
} else {
Serial.println(("Something went wrong during gesture sensor init!"));
}
}
void loop()
{
Blynk.run();
handleGesture();
DHT.read11(DHT11_PIN);
Blynk.virtualWrite(V3,DHT.temperature);
Blynk.virtualWrite(V4,DHT.humidity);
}
BLYNK_WRITE(V1)
{
digitalWrite(FANP, param.asInt());// turn the FAN on.(Note that LOW is the voltage level but actually
}
BLYNK_WRITE(V2)
{
digitalWrite(LED, param.asInt());// turn the LED on.(Note that LOW is the voltage level but actually
}