Skip to content
This repository was archived by the owner on Mar 17, 2025. It is now read-only.

Commit 7bad03f

Browse files
committed
Merge pull request #64 from gguuss/neopixel
Neopixel demo
2 parents 1126d81 + 5c12556 commit 7bad03f

File tree

7 files changed

+470
-0
lines changed

7 files changed

+470
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.DS_STORE
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
//
2+
// Copyright 2016 Google Inc.
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
//
16+
17+
// Firebase_ESP8266-Neopixel is a sample that demonstrates how
18+
// to set pixel data using a firebase stream.
19+
#include <Firebase.h>
20+
#include <ArduinoJson.h>
21+
22+
#include <Adafruit_NeoPixel.h>
23+
#include "colors_ext.h"
24+
25+
const int PIN=13;
26+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);
27+
28+
#define JSON_BUFFER_SIZE 10*4
29+
30+
// TODO: Replace with your own credentials and keep these safe.
31+
Firebase fbase = Firebase("YOUR-PROJECT.firebaseio.com")
32+
.auth("YOUR_AUTH_SECRET");
33+
34+
void setup() {
35+
Serial.begin(9600);
36+
37+
strip.begin();
38+
strip.setBrightness(25); // 0 ... 255
39+
strip.show(); // Initialize all pixels to 'off'
40+
41+
// Not connected, set the LEDs red
42+
colorWipe(&strip, 0xFF0000, 50);
43+
44+
// connect to wifi.
45+
WiFi.begin("GoogleGuest", "");
46+
Serial.print("connecting");
47+
48+
int count = 0;
49+
while (WiFi.status() != WL_CONNECTED) {
50+
// Draw rainbows while connecting
51+
Serial.print(".");
52+
if (count < strip.numPixels()){
53+
strip.setPixelColor(count++, Wheel(&strip, count * 8));
54+
strip.show();
55+
}
56+
delay(20);
57+
}
58+
Serial.println();
59+
Serial.print("connected: ");
60+
Serial.println(WiFi.localIP());
61+
62+
// Connected, set the LEDs green
63+
colorWipe(&strip, 0x00FF00, 50);
64+
}
65+
66+
67+
void loop() {
68+
// Get all entries.
69+
// TODO: Replace with streaming
70+
FirebaseGet get = fbase.get("/rgbdata");
71+
if (get.error()) {
72+
Serial.println("Firebase get failed");
73+
Serial.println(get.error().message());
74+
return;
75+
}
76+
77+
// Use dynamic for large JSON objects
78+
// DynamicJsonBuffer jsonBuffer;
79+
StaticJsonBuffer<JSON_OBJECT_SIZE(JSON_BUFFER_SIZE)> jsonBuffer;
80+
81+
// create an empty object
82+
String ref = get.json();
83+
Serial.println(ref);
84+
JsonObject& pixelJSON = jsonBuffer.parseObject((char*)ref.c_str());
85+
86+
if(pixelJSON.success()){
87+
for (int i=0; i < strip.numPixels(); i++) {
88+
String pixelAddress = "pixel" + String(i);
89+
String pixelVal = pixelJSON[pixelAddress];
90+
Serial.println(pixelVal);
91+
strip.setPixelColor(i, pixelVal.toInt());
92+
}
93+
strip.show();
94+
} else {
95+
Serial.println("Parse fail.");
96+
Serial.println(get.json());
97+
}
98+
}
99+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
// The following methods are extracted from the Adafruit Neopixel example, strandtest.
2+
// https://github.com/adafruit/Adafruit_NeoPixel
3+
4+
#ifndef COLORS_EXT_H
5+
#define COLORS_EXT_H
6+
7+
// Input a value 0 to 255 to get a color value.
8+
// The colours are a transition r - g - b - back to r.
9+
uint32_t Wheel(Adafruit_NeoPixel* strip, byte WheelPos) {
10+
WheelPos = 255 - WheelPos;
11+
if(WheelPos < 85) {
12+
return strip->Color(255 - WheelPos * 3, 0, WheelPos * 3);
13+
}
14+
if(WheelPos < 170) {
15+
WheelPos -= 85;
16+
return strip->Color(0, WheelPos * 3, 255 - WheelPos * 3);
17+
}
18+
WheelPos -= 170;
19+
return strip->Color(WheelPos * 3, 255 - WheelPos * 3, 0);
20+
}
21+
22+
23+
24+
// Fill the dots one after the other with a color
25+
void colorWipe(Adafruit_NeoPixel* strip, uint32_t c, uint8_t wait) {
26+
for(uint16_t i=0; i<strip->numPixels(); i++) {
27+
strip->setPixelColor(i, c);
28+
strip->show();
29+
delay(wait);
30+
}
31+
}
32+
33+
void rainbow(Adafruit_NeoPixel* strip, uint8_t wait) {
34+
uint16_t i, j;
35+
36+
for(j=0; j<256; j++) {
37+
for(i=0; i<strip->numPixels(); i++) {
38+
strip->setPixelColor(i, Wheel(strip, (i+j) & 255));
39+
}
40+
strip->show();
41+
delay(wait);
42+
}
43+
}
44+
45+
// Slightly different, this makes the rainbow equally distributed throughout
46+
void rainbowCycle(Adafruit_NeoPixel* strip, uint8_t wait) {
47+
uint16_t i, j;
48+
49+
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
50+
for(i=0; i< strip->numPixels(); i++) {
51+
strip->setPixelColor(i, Wheel(strip, ((i * 256 / strip->numPixels()) + j) & 255));
52+
}
53+
strip->show();
54+
delay(wait);
55+
}
56+
}
57+
58+
//Theatre-style crawling lights.
59+
void theaterChase(Adafruit_NeoPixel* strip, uint32_t c, uint8_t wait) {
60+
for (int j=0; j<10; j++) { //do 10 cycles of chasing
61+
for (int q=0; q < 3; q++) {
62+
for (int i=0; i < strip->numPixels(); i=i+3) {
63+
strip->setPixelColor(i+q, c); //turn every third pixel on
64+
}
65+
strip->show();
66+
67+
delay(wait);
68+
69+
for (int i=0; i < strip->numPixels(); i=i+3) {
70+
strip->setPixelColor(i+q, 0); //turn every third pixel off
71+
}
72+
}
73+
}
74+
}
75+
76+
//Theatre-style crawling lights with rainbow effect
77+
void theaterChaseRainbow(Adafruit_NeoPixel* strip, uint8_t wait) {
78+
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
79+
for (int q=0; q < 3; q++) {
80+
for (int i=0; i < strip->numPixels(); i=i+3) {
81+
strip->setPixelColor(i+q, Wheel(strip, (i+j) % 255)); //turn every third pixel on
82+
}
83+
strip->show();
84+
85+
delay(wait);
86+
87+
for (int i=0; i < strip->numPixels(); i=i+3) {
88+
strip->setPixelColor(i+q, 0); //turn every third pixel off
89+
}
90+
}
91+
}
92+
}
93+
#endif
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
bower_components/
2+
node_modules/
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Firebase Neopixel Web demo #
2+
3+
This demo console shows you how to synchronize data from the web to a device.
4+
5+
## Installation ##
6+
The demo uses [Bower](http://bower.io/) and
7+
[Polymer](http://www.polymer-project.org/) to simplify the UI and dependencies
8+
of the project.
9+
10+
For Bower, you need to install [Node.js](http://nodejs.org/). After node is
11+
installed, install the Bower package by calling:
12+
13+
`npm install -g bower`
14+
15+
After Bower is installed, you are ready to update the project dependencies with
16+
Bower by running:
17+
18+
`bower install`
19+
20+
With the dependencies set, serve the www folder from a web server. For example,
21+
you can use the Python Simple HTTP server module by running:
22+
23+
`python -m SimpleHTTPServer [port]`
24+
25+
With the web server running, navigate to /web-demo.html and you should see
26+
the demo load.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "web",
3+
"homepage": "https://github.com/gguuss/firebase-arduino",
4+
"authors": [
5+
"Gus Class <gguuss@gmail.com>"
6+
],
7+
"description": "",
8+
"main": "",
9+
"moduleType": [],
10+
"license": "MIT",
11+
"private": true,
12+
"ignore": [
13+
"**/.*",
14+
"node_modules",
15+
"bower_components",
16+
"test",
17+
"tests"
18+
],
19+
"dependencies": {
20+
"polymer": "^1.2.0",
21+
"polymer-color-picker": "^1.0.1"
22+
}
23+
}

0 commit comments

Comments
 (0)