Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commiteffe26d

Browse files
committed
Merge pull requestFirebaseExtended#132 from ed7coyne/room-example-to-constants
Switch to using const ints for room example
2 parents3b8ff0f +0d19a56 commiteffe26d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

‎examples/FirebaseRoom_ESP8266/FirebaseRoom_ESP8266.ino‎

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,24 @@
2020
#include<ESP8266WiFi.h>
2121
#include<FirebaseArduino.h>
2222

23+
constint pinGrove =15;
24+
constint pinVibrator =5;
25+
constint pinLightSensor = A0;
26+
constint pinLed =12;
27+
constint pinButton =14;
28+
constint pinFan =13;
29+
2330
voidsetup() {
2431
Serial.begin(9600);
2532

26-
// power grove connector
27-
pinMode(15, OUTPUT);
28-
digitalWrite(15, HIGH);
33+
pinMode(pinGrove, OUTPUT);
34+
digitalWrite(pinGrove, HIGH);
2935

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(pinVibrator, OUTPUT);
37+
pinMode(pinLightSensor, INPUT);
38+
pinMode(pinLed, OUTPUT);
39+
pinMode(pinButton, INPUT);
40+
pinMode(pinFan, OUTPUT);
4041

4142
// connect to wifi.
4243
WiFi.begin("SSID","PASSWORD");
@@ -48,23 +49,23 @@ void setup() {
4849
Serial.println();
4950
Serial.print("connected:");
5051
Serial.println(WiFi.localIP());
51-
52+
5253
Firebase.begin("example.firebaseio.com","secret_or_token");
5354
}
5455

5556
int button =0;
5657
float light =0.0;
5758

5859
voidloop() {
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(pinLed, (int)Firebase.get("redlight"));
61+
digitalWrite(pinFan, (int)Firebase.get("cooldown"));
62+
digitalWrite(pinVibrator, (int)Firebase.get("brrr"));
63+
int newButton =digitalRead(pinButton);
6364
if (newButton != button) {
6465
button = newButton;
6566
Firebase.set("pushbutton", button);
6667
}
67-
float newLight =analogRead(A0);
68+
float newLight =analogRead(pinLightSensor);
6869
if (abs(newLight - light) >100) {
6970
light = newLight;
7071
Firebase.set("sunlight", light);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp