16
16
17
17
// FirebaseNeoPixel is a sample that demonstrates how
18
18
// to set pixel data from Firebase.
19
- #include < Firebase .h>
19
+ #include < FirebaseArduino .h>
20
20
#include < ESP8266WiFi.h>
21
21
22
22
#include < Adafruit_NeoPixel.h>
23
- #include " colors_ext.h"
24
23
25
24
// Set these to run example.
26
25
#define FIREBASE_HOST " example.firebaseio.com"
31
30
const int PIN=13 ;
32
31
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32 , PIN, NEO_GRB + NEO_KHZ800);
33
32
34
- // TODO: Replace with your own credentials and keep these safe.
35
- Firebase fbase =Firebase(FIREBASE_HOST, FIREBASE_AUTH );
33
+ const int pixelPin = 13 ;
34
+ Adafruit_NeoPixel strip =Adafruit_NeoPixel( 32 , pixelPin, NEO_GRB + NEO_KHZ800 );
36
35
37
36
void setup () {
38
37
Serial.begin (9600 );
@@ -41,56 +40,35 @@ void setup() {
41
40
strip.setBrightness (25 );// 0 ... 255
42
41
strip.show ();// Initialize all pixels to 'off'
43
42
44
- // Not connected, set the LEDs red
45
- colorWipe (&strip,0xFF0000 ,50 );
46
-
47
43
// connect to wifi.
48
44
WiFi.begin (WIFI_SSID, WIFI_PASSWORD);
49
45
Serial.print (" connecting" );
50
-
51
- int count =0 ;
52
46
while (WiFi.status () != WL_CONNECTED) {
53
- // Draw rainbows while connecting
54
47
Serial.print (" ." );
55
- if (count < strip.numPixels ()){
56
- strip.setPixelColor (count++,Wheel (&strip, count *8 ));
57
- strip.show ();
58
- }
59
- delay (20 );
48
+ delay (500 );
60
49
}
61
50
Serial.println ();
62
51
Serial.print (" connected:" );
63
52
Serial.println (WiFi.localIP ());
64
53
65
- // Connected, set the LEDs green
66
- colorWipe (&strip,0x00FF00 ,50 );
54
+ Firebase.begin (" example.firebaseio.com" ," secret_or_token" );
67
55
}
68
56
69
57
70
58
void loop () {
71
59
// Get all entries.
72
60
// TODO: Replace with streaming
73
- FirebaseGet get =fbase .get (" /rgbdata" );
74
- if (get. error ()) {
61
+ FirebaseObject pixels =Firebase .get (" /rgbdata" );
62
+ if (Firebase. failed ()) {
75
63
Serial.println (" Firebase get failed" );
76
- Serial.println (get .error (). message ());
64
+ Serial.println (Firebase .error ());
77
65
return ;
78
66
}
79
67
80
- // create an empty object
81
- const JsonObject& pixelJSON = get.json ();
82
-
83
- if (pixelJSON.success ()){
84
- for (int i=0 ; i < strip.numPixels (); i++) {
85
- String pixelAddress =" pixel" +String (i);
86
- String pixelVal = pixelJSON[pixelAddress];
87
- Serial.println (pixelVal);
88
- strip.setPixelColor (i, pixelVal.toInt ());
89
- }
90
- strip.show ();
91
- }else {
92
- Serial.println (" Parse fail." );
93
- Serial.println (get.response ());
68
+ for (int i =0 ; i < strip.numPixels (); i++) {
69
+ int pixel = pixels.getInt (" pixel" + i);
70
+ Serial.println (pixel);
71
+ strip.setPixelColor (i, pixel);
94
72
}
73
+ strip.show ();
95
74
}
96
-