20
20
#include < ESP8266WiFi.h>
21
21
#include < FirebaseArduino.h>
22
22
23
+ const int pin_grove =15 ;
24
+ const int pin_vibrator =5 ;
25
+ const int pin_light_sensor = A0;
26
+ const int pin_led =12 ;
27
+ const int pin_button =14 ;
28
+ const int pin_fan =13 ;
29
+
23
30
void setup () {
24
31
Serial.begin (9600 );
25
32
26
- // power grove connector
27
- pinMode (15 , OUTPUT);
28
- digitalWrite (15 , HIGH);
33
+ pinMode (pin_grove, OUTPUT);
34
+ digitalWrite (pin_grove, HIGH);
29
35
30
- // pin 5 is connected to a vibrator motor.
31
- pinMode (5 , OUTPUT);
32
- // pin A0 is connected to a light sensor.
33
- pinMode (A0, INPUT);
34
- // pin 12 is connected to a red LED.
35
- pinMode (12 , OUTPUT);
36
- // pin 14 is connected to a push button.
37
- pinMode (14 , INPUT);
38
- // pin 13 is connected to a fan.
39
- pinMode (13 , OUTPUT);
36
+ pinMode (pin_vibrator, OUTPUT);
37
+ pinMode (pin_light_sensor, INPUT);
38
+ pinMode (pin_led, OUTPUT);
39
+ pinMode (pin_button, INPUT);
40
+ pinMode (pin_fan, OUTPUT);
40
41
41
42
// connect to wifi.
42
43
WiFi.begin (" SSID" ," PASSWORD" );
@@ -48,23 +49,23 @@ void setup() {
48
49
Serial.println ();
49
50
Serial.print (" connected:" );
50
51
Serial.println (WiFi.localIP ());
51
-
52
+
52
53
Firebase.begin (" example.firebaseio.com" ," secret_or_token" );
53
54
}
54
55
55
56
int button =0 ;
56
57
float light =0.0 ;
57
58
58
59
void loop () {
59
- digitalWrite (12 , (int )Firebase.get (" redlight" ));
60
- digitalWrite (13 , (int )Firebase.get (" cooldown" ));
61
- digitalWrite (5 , (int )Firebase.get (" brrr" ));
62
- int newButton =digitalRead (14 );
60
+ digitalWrite (pin_led , (int )Firebase.get (" redlight" ));
61
+ digitalWrite (pin_fan , (int )Firebase.get (" cooldown" ));
62
+ digitalWrite (pin_vibrator , (int )Firebase.get (" brrr" ));
63
+ int newButton =digitalRead (pin_button );
63
64
if (newButton != button) {
64
65
button = newButton;
65
66
Firebase.set (" pushbutton" , button);
66
67
}
67
- float newLight =analogRead (A0 );
68
+ float newLight =analogRead (pin_light_sensor );
68
69
if (abs (newLight - light) >100 ) {
69
70
light = newLight;
70
71
Firebase.set (" sunlight" , light);