Advertisement
bvoges

vivian

Jul 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.56 KB | None | 0 0
  1. #include <ESP8266WiFi.h>
  2. //#include <FirebaseArduino.h>
  3. //#define FIREBASE_HOST "YOUR_FIREBASE_PROJECT.firebaseio.com"
  4. //#define FIREBASE_AUTH "YOUR FIREBASE AUTHORIZATION KEY"
  5. #define WIFI_SSID "YOUR_SSID"
  6. #define WIFI_PASSWORD "YOUR_PASSWORD"
  7. #define RED_LED D2
  8. #define BLUE_LED D0
  9. #define BUTTON D3
  10. #define OFF 0
  11. #define REDE 1
  12. #define PURPLE 2
  13. int color = OFF;
  14. void setup()
  15. {
  16. Serial.begin(9600);
  17. // setupWiFi();
  18.  
  19. pinMode(RED_LED, OUTPUT);
  20. pinMode(BLUE_LED, OUTPUT);
  21. digitalWrite(RED_LED, HIGH);
  22. digitalWrite(BLUE_LED, HIGH);
  23.  
  24. // Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);
  25. // Firebase.setString("share/colorState", "red");
  26. // if(Firebase.success()){
  27. // Serial.print("Firebase write success!");
  28. // } else {
  29. // Serial.print("Firebase write failed!");
  30. // Serial.println("");
  31. // Serial.print(Firebase.error());
  32. // }
  33. Serial.println("");
  34. }
  35.  
  36. int timePassed (int time) {
  37. int diff = 0;
  38. if (millis() <= time) {
  39. diff = (69666 - time) + millis();
  40. } else {
  41. diff = millis() - time;
  42. }
  43. return diff;
  44. }
  45.  
  46. //int checkFirebaseTime = 0;
  47. //String colorState = "red";
  48. bool press = false;
  49. void loop()
  50. {
  51. if(!digitalRead(BUTTON) && press == true) // button was released
  52. {
  53. Serial.println(" button released");
  54. updateLED();
  55. press = false;
  56. } else
  57. if (digitalRead(BUTTON) && press == false) // button was pressed
  58. {
  59. Serial.println(" button pressed");
  60. press = true;
  61. }
  62. // if(colorState == "red") colorState = "purple";
  63. // else colorState = "red";
  64. // }
  65. // if (timePassed (checkFirebaseTime) >= 100) {
  66. // Serial.println(digitalRead(BUTTON));
  67. // String fbColorState = Firebase.getString("share/colorState");
  68. // if(fbColorState != colorState){
  69. // colorState = fbColorState;
  70. // toggleLED();
  71. // }
  72. // checkFirebaseTime = millis();
  73. // }
  74. }
  75.  
  76. void toggleLED(){
  77. digitalWrite(BLUE_LED,!digitalRead(BLUE_LED));
  78. }
  79.  
  80. void updateLED(){
  81.  
  82. if(color = OFF)
  83. {
  84. digitalWrite(RED_LED, LOW);
  85. color = REDE;
  86. }
  87. else if(color = REDE)
  88. {
  89. digitalWrite(BLUE_LED, LOW);
  90. color = PURPLE;
  91. }
  92. else if(color = PURPLE)
  93. {
  94. digitalWrite(RED_LED, HIGH);
  95. digitalWrite(BLUE_LED, HIGH);
  96. color = OFF;
  97. }
  98. }
  99. void setupWiFi()
  100. {
  101. WiFi.mode(WIFI_STA);
  102. WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  103. Serial.print("connecting");
  104. while (WiFi.status() != WL_CONNECTED) {
  105. Serial.print(".");
  106. delay(500);
  107. }
  108. Serial.println();
  109. Serial.print("Connected to ");
  110. Serial.println(WiFi.SSID());
  111. Serial.println();
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement