Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc68307a

Browse files
committed
A basic demo of Web + Arduino control of an Adafruit Neopixel feather shield
1 parent409c806 commitc68307a

File tree

6 files changed

+453
-0
lines changed

6 files changed

+453
-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: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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+
#definePIN13
26+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(32, PIN, NEO_GRB + NEO_KHZ800);
27+
28+
29+
// TODO: Replace with your own credentials and keep these safe.
30+
Firebase fbase = Firebase("brilliant-fire-9638.firebaseio.com")
31+
.auth("llXzJtqwdiHCHw6F6sehQR2EPwbO0YYdhEjPRZxG");
32+
33+
voidsetup() {
34+
Serial.begin(9600);
35+
36+
strip.begin();
37+
strip.setBrightness(25);// 0 ... 255
38+
strip.show();// Initialize all pixels to 'off'
39+
40+
colorWipe(&strip,0xFF0000,50);
41+
42+
// connect to wifi.
43+
WiFi.begin("GoogleGuest","");
44+
Serial.print("connecting");
45+
46+
int count =0;
47+
while (WiFi.status() != WL_CONNECTED) {
48+
// Draw rainbows while connecting
49+
Serial.print(".");
50+
if (count < strip.numPixels()){
51+
strip.setPixelColor(count++,Wheel(&strip, count *8));
52+
strip.show();
53+
}
54+
delay(20);
55+
}
56+
Serial.println();
57+
Serial.print("connected:");
58+
Serial.println(WiFi.localIP());
59+
60+
// Connected, set the LEDs green
61+
colorWipe(&strip,0x00FF00,50);
62+
}
63+
64+
65+
voidloop() {
66+
// Get all entries.
67+
// TODO: Replace with streaming
68+
FirebaseGet get = fbase.get("/rgbdata");
69+
if (get.error()) {
70+
Serial.println("Firebase get failed");
71+
Serial.println(get.error().message());
72+
return;
73+
}
74+
75+
// Use dynamic for large JSON objects
76+
// DynamicJsonBuffer jsonBuffer;
77+
StaticJsonBuffer<JSON_OBJECT_SIZE(10*4)> jsonBuffer;
78+
79+
// create an empty object
80+
String ref = get.json();
81+
Serial.println(ref);
82+
JsonObject& pixelJSON = jsonBuffer.parseObject((char*)ref.c_str());
83+
84+
if(pixelJSON.success()){
85+
for (int i=0; i < strip.numPixels(); i++) {
86+
String pixelAddress ="pixel" +String(i);
87+
String pixelVal = pixelJSON[pixelAddress];
88+
Serial.println(pixelVal);
89+
strip.setPixelColor(i, pixelVal.toInt());
90+
91+
// Don't do this: it will waste tons of memory due to the way that the
92+
// Arduino JSON library handles elements.
93+
/*
94+
int r = (uint32_t) pixelJSON[pixelAddress]["r"];
95+
int g = (uint32_t) pixelJSON[pixelAddress]["g"];
96+
int b = (uint32_t) pixelJSON[pixelAddress]["b"];
97+
98+
Serial.println("Setting [" + String(i) + "] to {" + String(r) + "," + String(g) + "," + String(b) + "}");
99+
strip.setPixelColor(i, strip.Color(r, g, b));
100+
*/
101+
}
102+
strip.show();
103+
}else {
104+
Serial.println("Parse fail.");
105+
Serial.println(get.json());
106+
}
107+
}
108+
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+
#ifndefCOLORS_EXT_H
5+
#defineCOLORS_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_tWheel(Adafruit_NeoPixel*strip,byteWheelPos) {
10+
WheelPos=255-WheelPos;
11+
if(WheelPos<85) {
12+
returnstrip->Color(255-WheelPos*3,0,WheelPos*3);
13+
}
14+
if(WheelPos<170) {
15+
WheelPos-=85;
16+
returnstrip->Color(0,WheelPos*3,255-WheelPos*3);
17+
}
18+
WheelPos-=170;
19+
returnstrip->Color(WheelPos*3,255-WheelPos*3,0);
20+
}
21+
22+
23+
24+
// Fill the dots one after the other with a color
25+
voidcolorWipe(Adafruit_NeoPixel*strip,uint32_tc,uint8_twait) {
26+
for(uint16_ti=0;i<strip->numPixels();i++) {
27+
strip->setPixelColor(i,c);
28+
strip->show();
29+
delay(wait);
30+
}
31+
}
32+
33+
voidrainbow(Adafruit_NeoPixel*strip,uint8_twait) {
34+
uint16_ti,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+
voidrainbowCycle(Adafruit_NeoPixel*strip,uint8_twait) {
47+
uint16_ti,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+
voidtheaterChase(Adafruit_NeoPixel*strip,uint32_tc,uint8_twait) {
60+
for (intj=0;j<10;j++) {//do 10 cycles of chasing
61+
for (intq=0;q<3;q++) {
62+
for (inti=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 (inti=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+
voidtheaterChaseRainbow(Adafruit_NeoPixel*strip,uint8_twait) {
78+
for (intj=0;j<256;j++) {// cycle all 256 colors in the wheel
79+
for (intq=0;q<3;q++) {
80+
for (inti=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 (inti=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: 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)

[8]ページ先頭

©2009-2025 Movatter.jp