This repository was archived by the owner on Mar 17, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 492
Neopixel demo #64
Merged
Merged
Neopixel demo #64
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
examples/Firebase_ESP8266_LEDs/Firebase_ESP8266_Neopixel/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.DS_STORE |
99 changes: 99 additions & 0 deletions
99
examples/Firebase_ESP8266_LEDs/Firebase_ESP8266_Neopixel/Firebase_ESP8266_Neopixel.ino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
// | ||
// Copyright 2016 Google Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
// Firebase_ESP8266-Neopixel is a sample that demonstrates how | ||
// to set pixel data using a firebase stream. | ||
#include <Firebase.h> | ||
#include <ArduinoJson.h> | ||
|
||
#include <Adafruit_NeoPixel.h> | ||
#include "colors_ext.h" | ||
|
||
const int PIN=13; | ||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
#define JSON_BUFFER_SIZE 10*4 | ||
|
||
// TODO: Replace with your own credentials and keep these safe. | ||
Firebase fbase = Firebase("YOUR-PROJECT.firebaseio.com") | ||
.auth("YOUR_AUTH_SECRET"); | ||
|
||
void setup() { | ||
Serial.begin(9600); | ||
|
||
strip.begin(); | ||
strip.setBrightness(25); // 0 ... 255 | ||
strip.show(); // Initialize all pixels to 'off' | ||
|
||
// Not connected, set the LEDs red | ||
colorWipe(&strip, 0xFF0000, 50); | ||
|
||
// connect to wifi. | ||
WiFi.begin("GoogleGuest", ""); | ||
Serial.print("connecting"); | ||
|
||
int count = 0; | ||
while (WiFi.status() != WL_CONNECTED) { | ||
// Draw rainbows while connecting | ||
Serial.print("."); | ||
if (count < strip.numPixels()){ | ||
strip.setPixelColor(count++, Wheel(&strip, count * 8)); | ||
strip.show(); | ||
} | ||
delay(20); | ||
} | ||
Serial.println(); | ||
Serial.print("connected: "); | ||
Serial.println(WiFi.localIP()); | ||
|
||
// Connected, set the LEDs green | ||
colorWipe(&strip, 0x00FF00, 50); | ||
} | ||
|
||
|
||
void loop() { | ||
// Get all entries. | ||
// TODO: Replace with streaming | ||
FirebaseGet get = fbase.get("/rgbdata"); | ||
if (get.error()) { | ||
Serial.println("Firebase get failed"); | ||
Serial.println(get.error().message()); | ||
return; | ||
} | ||
|
||
// Use dynamic for large JSON objects | ||
// DynamicJsonBuffer jsonBuffer; | ||
StaticJsonBuffer<JSON_OBJECT_SIZE(JSON_BUFFER_SIZE)> jsonBuffer; | ||
|
||
// create an empty object | ||
String ref = get.json(); | ||
Serial.println(ref); | ||
JsonObject& pixelJSON = jsonBuffer.parseObject((char*)ref.c_str()); | ||
|
||
if(pixelJSON.success()){ | ||
for (int i=0; i < strip.numPixels(); i++) { | ||
String pixelAddress = "pixel" + String(i); | ||
String pixelVal = pixelJSON[pixelAddress]; | ||
Serial.println(pixelVal); | ||
strip.setPixelColor(i, pixelVal.toInt()); | ||
} | ||
strip.show(); | ||
} else { | ||
Serial.println("Parse fail."); | ||
Serial.println(get.json()); | ||
} | ||
} | ||
|
93 changes: 93 additions & 0 deletions
93
examples/Firebase_ESP8266_LEDs/Firebase_ESP8266_Neopixel/colors_ext.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// The following methods are extracted from the Adafruit Neopixel example, strandtest. | ||
// https://github.com/adafruit/Adafruit_NeoPixel | ||
|
||
#ifndef COLORS_EXT_H | ||
#define COLORS_EXT_H | ||
|
||
// Input a value 0 to 255 to get a color value. | ||
// The colours are a transition r - g - b - back to r. | ||
uint32_t Wheel(Adafruit_NeoPixel* strip, byte WheelPos) { | ||
WheelPos = 255 - WheelPos; | ||
if(WheelPos < 85) { | ||
return strip->Color(255 - WheelPos * 3, 0, WheelPos * 3); | ||
} | ||
if(WheelPos < 170) { | ||
WheelPos -= 85; | ||
return strip->Color(0, WheelPos * 3, 255 - WheelPos * 3); | ||
} | ||
WheelPos -= 170; | ||
return strip->Color(WheelPos * 3, 255 - WheelPos * 3, 0); | ||
} | ||
|
||
|
||
|
||
// Fill the dots one after the other with a color | ||
void colorWipe(Adafruit_NeoPixel* strip, uint32_t c, uint8_t wait) { | ||
for(uint16_t i=0; i<strip->numPixels(); i++) { | ||
strip->setPixelColor(i, c); | ||
strip->show(); | ||
delay(wait); | ||
} | ||
} | ||
|
||
void rainbow(Adafruit_NeoPixel* strip, uint8_t wait) { | ||
uint16_t i, j; | ||
|
||
for(j=0; j<256; j++) { | ||
for(i=0; i<strip->numPixels(); i++) { | ||
strip->setPixelColor(i, Wheel(strip, (i+j) & 255)); | ||
} | ||
strip->show(); | ||
delay(wait); | ||
} | ||
} | ||
|
||
// Slightly different, this makes the rainbow equally distributed throughout | ||
void rainbowCycle(Adafruit_NeoPixel* strip, uint8_t wait) { | ||
uint16_t i, j; | ||
|
||
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel | ||
for(i=0; i< strip->numPixels(); i++) { | ||
strip->setPixelColor(i, Wheel(strip, ((i * 256 / strip->numPixels()) + j) & 255)); | ||
} | ||
strip->show(); | ||
delay(wait); | ||
} | ||
} | ||
|
||
//Theatre-style crawling lights. | ||
void theaterChase(Adafruit_NeoPixel* strip, uint32_t c, uint8_t wait) { | ||
for (int j=0; j<10; j++) { //do 10 cycles of chasing | ||
for (int q=0; q < 3; q++) { | ||
for (int i=0; i < strip->numPixels(); i=i+3) { | ||
strip->setPixelColor(i+q, c); //turn every third pixel on | ||
} | ||
strip->show(); | ||
|
||
delay(wait); | ||
|
||
for (int i=0; i < strip->numPixels(); i=i+3) { | ||
strip->setPixelColor(i+q, 0); //turn every third pixel off | ||
} | ||
} | ||
} | ||
} | ||
|
||
//Theatre-style crawling lights with rainbow effect | ||
void theaterChaseRainbow(Adafruit_NeoPixel* strip, uint8_t wait) { | ||
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel | ||
for (int q=0; q < 3; q++) { | ||
for (int i=0; i < strip->numPixels(); i=i+3) { | ||
strip->setPixelColor(i+q, Wheel(strip, (i+j) % 255)); //turn every third pixel on | ||
} | ||
strip->show(); | ||
|
||
delay(wait); | ||
|
||
for (int i=0; i < strip->numPixels(); i=i+3) { | ||
strip->setPixelColor(i+q, 0); //turn every third pixel off | ||
} | ||
} | ||
} | ||
} | ||
#endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bower_components/ | ||
node_modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Firebase Neopixel Web demo # | ||
|
||
This demo console shows you how to synchronize data from the web to a device. | ||
|
||
## Installation ## | ||
The demo uses [Bower](http://bower.io/) and | ||
[Polymer](http://www.polymer-project.org/) to simplify the UI and dependencies | ||
of the project. | ||
|
||
For Bower, you need to install [Node.js](http://nodejs.org/). After node is | ||
installed, install the Bower package by calling: | ||
|
||
`npm install -g bower` | ||
|
||
After Bower is installed, you are ready to update the project dependencies with | ||
Bower by running: | ||
|
||
`bower install` | ||
|
||
With the dependencies set, serve the www folder from a web server. For example, | ||
you can use the Python Simple HTTP server module by running: | ||
|
||
`python -m SimpleHTTPServer [port]` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe you could use https://github.com/PolymerLabs/polyserve? |
||
|
||
With the web server running, navigate to /web-demo.html and you should see | ||
the demo load. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"name": "web", | ||
"homepage": "https://github.com/gguuss/firebase-arduino", | ||
"authors": [ | ||
"Gus Class <gguuss@gmail.com>" | ||
], | ||
"description": "", | ||
"main": "", | ||
"moduleType": [], | ||
"license": "MIT", | ||
"private": true, | ||
"ignore": [ | ||
"**/.*", | ||
"node_modules", | ||
"bower_components", | ||
"test", | ||
"tests" | ||
], | ||
"dependencies": { | ||
"polymer": "^1.2.0", | ||
"polymer-color-picker": "^1.0.1" | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use the same placeholder that we use in the other sample:
https://github.com/googlesamples/firebase-arduino/blob/master/examples/FirebasePush_ESP8266/FirebasePush_ESP8266.ino#L23
Or change the other sample to use yours :) (I'm not sure Project ID is in firebase jargon)