Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- //#include <FirebaseArduino.h>
- //#define FIREBASE_HOST "YOUR_FIREBASE_PROJECT.firebaseio.com"
- //#define FIREBASE_AUTH "YOUR FIREBASE AUTHORIZATION KEY"
- #define WIFI_SSID "YOUR_SSID"
- #define WIFI_PASSWORD "YOUR_PASSWORD"
- #define RED_LED D2
- #define BLUE_LED D0
- #define BUTTON D3
- #define OFF 0
- #define REDE 1
- #define PURPLE 2
- int color = OFF;
- void setup()
- {
- Serial.begin(9600);
- // setupWiFi();
- pinMode(RED_LED, OUTPUT);
- pinMode(BLUE_LED, OUTPUT);
- digitalWrite(RED_LED, HIGH);
- digitalWrite(BLUE_LED, HIGH);
- // Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
- // Firebase.setString("share/colorState", "red");
- // if(Firebase.success()){
- // Serial.print("Firebase write success!");
- // } else {
- // Serial.print("Firebase write failed!");
- // Serial.println("");
- // Serial.print(Firebase.error());
- // }
- Serial.println("");
- }
- int timePassed (int time) {
- int diff = 0;
- if (millis() <= time) {
- diff = (69666 - time) + millis();
- } else {
- diff = millis() - time;
- }
- return diff;
- }
- //int checkFirebaseTime = 0;
- //String colorState = "red";
- bool press = false;
- void loop()
- {
- if(!digitalRead(BUTTON) && press == true) // button was released
- {
- Serial.println(" button released");
- updateLED();
- press = false;
- } else
- if (digitalRead(BUTTON) && press == false) // button was pressed
- {
- Serial.println(" button pressed");
- press = true;
- }
- // if(colorState == "red") colorState = "purple";
- // else colorState = "red";
- // }
- // if (timePassed (checkFirebaseTime) >= 100) {
- // Serial.println(digitalRead(BUTTON));
- // String fbColorState = Firebase.getString("share/colorState");
- // if(fbColorState != colorState){
- // colorState = fbColorState;
- // toggleLED();
- // }
- // checkFirebaseTime = millis();
- // }
- }
- void toggleLED(){
- digitalWrite(BLUE_LED,!digitalRead(BLUE_LED));
- }
- void updateLED(){
- if(color = OFF)
- {
- digitalWrite(RED_LED, LOW);
- color = REDE;
- }
- else if(color = REDE)
- {
- digitalWrite(BLUE_LED, LOW);
- color = PURPLE;
- }
- else if(color = PURPLE)
- {
- digitalWrite(RED_LED, HIGH);
- digitalWrite(BLUE_LED, HIGH);
- color = OFF;
- }
- }
- void setupWiFi()
- {
- WiFi.mode(WIFI_STA);
- WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
- Serial.print("connecting");
- while (WiFi.status() != WL_CONNECTED) {
- Serial.print(".");
- delay(500);
- }
- Serial.println();
- Serial.print("Connected to ");
- Serial.println(WiFi.SSID());
- Serial.println();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement