Diff
checker
Testo
Testo
Immagini
Documenti
Excel
Cartelle
Legal
Enterprise
Applicazione per desktop
Prezzi
Accedi
Scarica Diffchecker Desktop
Confronta il testo
Trova la differenza tra due file di testo
Strumenti
Cronologia
Editor live
Nascondi spazi bianchi
Comprimi invariate
Senza a capo
Layout
Diviso
Unificato
Livello di dettaglio
Intelligente
Parola
Carattere
Stili testo
Modifica aspetto
Evidenziazione sintassi
Scegli sintassi
Ignora
Trasforma testo
Vai alla prima modifica
Modifica input
Diffchecker Desktop
Il modo più sicuro per usare Diffchecker. Ottieni l'app Diffchecker Desktop: i tuoi diff non lasciano mai il tuo computer!
Ottieni Desktop
LED_Remote
Creato
4 anni fa
Il diff non scade mai
Eliminare
Esporta
Condividere
Spiegare
28 rimozioni
Linee
Totale
Rimosso
Caratteri
Totale
Rimosso
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
227 linee
Copia tutti
397 aggiunte
Linee
Totale
Aggiunto
Caratteri
Totale
Aggiunto
Per continuare a utilizzare questa funzione, aggiorna a
Diff
checker
Pro
Visualizza prezzi
533 linee
Copia tutti
/* =================================================================
/* =================================================================
Copia
Copiato
Copia
Copiato
* LED Remote
* LED Remote
Copia
Copiato
Copia
Copiato
* (c) Brooke. 2016
* (c) Brooke. 2016
-2020
Copia
Copiato
Copia
Copiato
* This file is the firmware to be upload and ran on the photon. It makes use of the particle API.
* This file is the firmware to be upload and ran on the photon. It makes use of the particle API.
Copia
Copiato
Copia
Copiato
* All original code is under the GPL v3 except where listed.
* All original code is under the GPL v3 except where listed.
Copia
Copiato
Copia
Copiato
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
Copia
Copiato
Copia
Copiato
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU General Public License as published by
Copia
Copiato
Copia
Copiato
* the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or
Copia
Copiato
Copia
Copiato
* (at your option) any later version.
* (at your option) any later version.
Copia
Copiato
Copia
Copiato
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
Copia
Copiato
Copia
Copiato
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
Copia
Copiato
Copia
Copiato
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Copia
Copiato
Copia
Copiato
* GNU General Public License for more details.
* GNU General Public License for more details.
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
Copia
Copiato
Copia
Copiato
* along with this program; if not, write to the Free Software
* along with this program; if not, write to the Free Software
Copia
Copiato
Copia
Copiato
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301
USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301
USA
================================================================= */
================================================================= */
Copia
Copiato
Copia
Copiato
/* =======================
i
ncludes ================================= */
#include <neopixel.h>
// use for Build IDE
// #include
"neopixel.h
" // use for local build
/* =======================
I
ncludes ================================= */
#include <neopixel.h>
// #include
\
"neopixel.h
\
" // use for local build
/* ======================= Constances====================== */
/* ======================= Constances====================== */
Copia
Copiato
Copia
Copiato
SYSTEM_MODE(AUTOMATIC);
SYSTEM_MODE(AUTOMATIC);
Copia
Copiato
Copia
Copiato
#define PIXEL_PIN
2
#define PIXEL_COUNT
58
#define PIXEL_PIN
6
#define PIXEL_COUNT
120
#define PIXEL_TYPE SK6812RGBW
#define PIXEL_TYPE SK6812RGBW
Copia
Copiato
Copia
Copiato
#define BRIGHTNESS 255
#define BRIGHTNESS 255
Copia
Copiato
Copia
Copiato
uint8_t setStripBrigtness( String brightnessValue) ;
uint8_t setStripBrigtness( String brightnessValue) ;
Copia
Copiato
Copia
Copiato
int
setStripColor( String hexValue );
int
setStripColor( String hexValue );
int currentBrightness = 0;
int currentBrightness = 0;
Copia
Copiato
Copia
Copiato
String currentHex =
"";
String currentHex =
\"\";
uint8_t setStripPower( String powerValue );
int currentPower = 2;
int loopCase = 0;
int loopCase = 0;
Copia
Copiato
Copia
Copiato
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
Copia
Copiato
Copia
Copiato
/**
/**
* setup -- Standard Arduino setup() function
* setup -- Standard Arduino setup() function
Copia
Copiato
Copia
Copiato
**/
**/
Copia
Copiato
Copia
Copiato
void setup (){
void setup (){
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
strip.begin();
strip.begin();
Copia
Copiato
Copia
Copiato
strip.show(); // Initialize all pixels to 'off'
strip.show(); // Initialize all pixels to 'off'
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
//Particle Functions for Color and Brightness
//Particle Functions for Color and Brightness
Copia
Copiato
Copia
Copiato
Particle.function(
"hex
", setStripColor);
Particle.function(
"bri
", setStripBrigtness);
Particle.function(
\
"hex
\
", setStripColor);
Particle.function(
\
"bri
\
", setStripBrigtness);
Particle.function(\"pwr\", setStripPower);
Copia
Copiato
Copia
Copiato
//Particle Variable to hold brightness value
:
Particle.variable(
"curBri
", currentBrightness);
//Particle Variable to hold brightness value
. Shoudl return between 0 - 255
Particle.variable(
\
"curBri
\
", currentBrightness);
Copia
Copiato
Copia
Copiato
//Particle Variable to hold color value
:
Particle.variable(
"curHex
", currentHex);
//Particle Variable to hold color value
. Should return hex or -1 for false
Particle.variable(
\
"curHex
\
", currentHex);
Copia
Copiato
Copia
Copiato
}
//Particle Variable to hold power value. Should always return 1 or 2.
Particle.variable(\"curPwr\", currentPower);
}
Copia
Copiato
Copia
Copiato
/**
/**
Copia
Copiato
Copia
Copiato
* loop -- Standard Arduino loop() function
**/
* loop -- Standard Arduino loop() function
**/
void loop (){
void loop (){
Copia
Copiato
Copia
Copiato
switch ( loopCase ) {
switch ( loopCase ) {
Copia
Copiato
Copia
Copiato
case 1:
case 1:
Copia
Copiato
Copia
Copiato
setHex(currentHex);
setHex(currentHex);
Copia
Copiato
Copia
Copiato
break;
break;
Copia
Copiato
Copia
Copiato
case 2:
case 2:
Copia
Copiato
Copia
Copiato
rainbowCycle(20);
rainbowCycle(20);
Copia
Copiato
Copia
Copiato
break;
break;
Copia
Copiato
Copia
Copiato
case 3:
case 3:
Copia
Copiato
Copia
Copiato
rainbow(20);
rainbow(20);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
delay(20);
delay(20);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
/**
/**
Copia
Copiato
Copia
Copiato
* getStripColor -- gets the HexValue input from our POST request
* @param hexValue -- gets hex value string from Particle API
* getStripColor -- gets the HexValue input from our POST request
*/
* @param hexValue -- gets hex value string from Particle API
*/
int setStripColor( String hexValue ) {
int setStripColor( String hexValue ) {
Copia
Copiato
Copia
Copiato
if(hexValue.length() == 8){
if(hexValue.length() == 8){
Copia
Copiato
Copia
Copiato
currentHex = hexValue;
currentHex = hexValue;
Copia
Copiato
Copia
Copiato
loopCase = 1;
loopCase = 1;
Copia
Copiato
Copia
Copiato
return 1;
return 1;
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
else if( hexValue ==
"rainbow
" ) {
else if( hexValue ==
\
"rainbow
\
" ) {
loopCase = 2;
loopCase = 2;
Copia
Copiato
Copia
Copiato
return 2;
return 2;
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
else if ( hexValue ==
"rainbowCycle
" ) {
else if ( hexValue ==
\
"rainbowCycle
\
" ) {
loopCase = 3;
loopCase = 3;
Copia
Copiato
Copia
Copiato
return 3;
return 3;
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
else {
else {
Copia
Copiato
Copia
Copiato
return -1;
return -1;
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
/**
/**
* setStripBrightness -- Sets the LED strip color based on input of particle function setStripBrigtness
* setStripBrightness -- Sets the LED strip color based on input of particle function setStripBrigtness
Copia
Copiato
Copia
Copiato
* @param brightnessValue -- 0-255 brightness value for our LED strip.
* @param brightnessValue -- 0-255 brightness value for our LED strip.
Copia
Copiato
Copia
Copiato
*/
*/
Copia
Copiato
Copia
Copiato
uint8_t setStripBrigtness( String brightnessValue ) {
uint8_t setStripBrigtness( String brightnessValue ) {
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
uint8_t brightnessAsInt = brightnessValue.toInt();
uint8_t brightnessAsInt = brightnessValue.toInt();
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){
if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){
Copia
Copiato
Copia
Copiato
for (uint8_t i = 0; i < PIXEL_COUNT; i
++ ){
for (uint8_t i = 0; i < PIXEL_COUNT; i
= i + currentPower ){
strip.setBrightness( brightnessAsInt );
strip.setBrightness( brightnessAsInt );
Copia
Copiato
Copia
Copiato
strip.show();
}
}
Copia
Copiato
Copia
Copiato
strip.show();
currentBrightness = brightnessAsInt;
currentBrightness = brightnessAsInt;
Copia
Copiato
Copia
Copiato
return currentBrightness;
return currentBrightness;
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
else {
else {
Copia
Copiato
Copia
Copiato
return 0;
return 0;
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
/**
/**
Copia
Copiato
Copia
Copiato
* convertHex -- converts hexValue into byte to be used in our array RBG > 255
* see: https://arduino.stackexchange.com/a/16446
* setStripPower -- Sets the strip power
* @param char -- gets hex value string from Particle API
*/
* @param powerValue -- Send 1 for all lights and send 0 for just half.
*/
uint8_t setStripPower( String powerValue ) {
if( powerValue.toInt() == 1 ){
currentPower = 1;
return 1;
}
else {
currentPower = 2;
return 0;
}
}
/**
* convertHex -- converts hexValue into byte to be used in our array RBG > 255
* see: https://arduino.stackexchange.com/a/16446
* @param char -- gets hex value string from Particle API
*/
byte convertHex (const char * str){
byte convertHex (const char * str){
Copia
Copiato
Copia
Copiato
char c = str [0] - '0';
char c = str [0] - '0';
Copia
Copiato
Copia
Copiato
if (c > 9)
if (c > 9)
Copia
Copiato
Copia
Copiato
c -= 7;
c -= 7;
Copia
Copiato
Copia
Copiato
int result = c;
int result = c;
Copia
Copiato
Copia
Copiato
c = str [1] - '0';
c = str [1] - '0';
Copia
Copiato
Copia
Copiato
if (c > 9)
if (c > 9)
Copia
Copiato
Copia
Copiato
c -= 7;
c -= 7;
Copia
Copiato
Copia
Copiato
return (result << 4) | c;
return (result << 4) | c;
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
/**
/**
Copia
Copiato
Copia
Copiato
* setHex -- converts hexValue into byte to be used in our array RBG > 255
* @param hexValue HexValue to set strip to.
* setHex -- converts hexValue into byte to be used in our array RBG > 255
*/
* @param hexValue HexValue to set strip to.
*/
Copia
Copiato
Copia
Copiato
char setHex( String hexValue ) {
char setHex( String hexValue ) {
Copia
Copiato
Copia
Copiato
const char * hexCharArray = hexValue;
const char * hexCharArray = hexValue;
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
byte redValue = convertHex ( & hexCharArray[0] );
byte redValue = convertHex ( & hexCharArray[0] );
Copia
Copiato
Copia
Copiato
byte greenValue = convertHex ( & hexCharArray[2] );
byte greenValue = convertHex ( & hexCharArray[2] );
Copia
Copiato
Copia
Copiato
byte blueValue = convertHex ( & hexCharArray[4] );
byte blueValue = convertHex ( & hexCharArray[4] );
Copia
Copiato
Copia
Copiato
byte whiteValue = convertHex ( & hexCharArray[6] );
byte whiteValue = convertHex ( & hexCharArray[6] );
Copia
Copiato
Copia
Copiato
Copia
Copiato
Copia
Copiato
for (int i = 0; i < PIXEL_COUNT; i
++ ){
if( currentPower == 2 ){
for (int i = 1; i < PIXEL_COUNT; i++ ){
strip.setPixelColor(i, 0, 0, 0, 0);
}
}
for (int i = 0; i < PIXEL_COUNT; i
= i + currentPower ){
strip.setPixelColor(i, greenValue, redValue, blueValue, whiteValue);
strip.setPixelColor(i, greenValue, redValue, blueValue, whiteValue);
Copia
Copiato
Copia
Copiato
strip.show();
}
}
Copia
Copiato
Copia
Copiato
strip.show();
}
}
Copia
Copiato
Copia
Copiato
/**
/**
Copia
Copiato
Copia
Copiato
* rainbowCycle -- Cycles through colors
* @source: https://github.com/adafruit/Adafruit_NeoPixel
* rainbowCycle -- Cycles through colors
* @param wait -- mills between transition, higher is slower. Vaules 0-255
*/
* @source: https://github.com/adafruit/Adafruit_NeoPixel
* @param wait -- mills between transition, higher is slower. Vaules 0-255
*/
void rainbowCycle(uint8_t wait) {
void rainbowCycle(uint8_t wait) {
Copia
Copiato
Copia
Copiato
uint16_t i, j;
uint16_t i, j;
Copia
Copiato
Copia
Copiato
for(j=0; j<256; j++) { // 5 cycles of all colors on wheel
for(j=0; j<256; j++) { // 5 cycles of all colors on wheel
Copia
Copiato
Copia
Copiato
for(i=0; i< strip.numPixels(); i
++
) {
strip.setPixelColor(i, Wheel(((i * 256 /
strip.numPixels()
) + j) & 255));
if( currentPower == 2 ){
for (int i = 1; i < PIXEL_COUNT; i++ ){
strip.setPixelColor(i, 0, 0, 0, 0);
}
}
for(i=0; i< strip.numPixels(); i
= i + currentPower
) {
strip.setPixelColor(i, Wheel(((i * 256 /
PIXEL_COUNT
) + j) & 255));
}
}
Copia
Copiato
Copia
Copiato
strip.show();
strip.show();
Copia
Copiato
Copia
Copiato
delay(wait);
delay(wait);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
/**
/**
Copia
Copiato
Copia
Copiato
* rainbow -- Cycles through colors
* @source: https://github.com/adafruit/Adafruit_NeoPixel
* rainbow -- Cycles through colors
* @param wait -- mills between transition, higher is slower. Vaules 0-255
*/
* @source: https://github.com/adafruit/Adafruit_NeoPixel
* @param wait -- mills between transition, higher is slower. Vaules 0-255
*/
void rainbow(uint8_t wait) {
void rainbow(uint8_t wait) {
Copia
Copiato
Copia
Copiato
uint16_t i, j;
uint16_t i, j;
Copia
Copiato
Copia
Copiato
for(j=0; j<256; j++) {
for(j=0; j<256; j++) {
Copia
Copiato
Copia
Copiato
for(i=0; i<strip.numPixels(); i
++
) {
if( currentPower == 2 ){
for (int i = 1; i < PIXEL_COUNT; i++ ){
strip.setPixelColor(i, 0, 0, 0, 0);
}
}
for(i=0; i<strip.numPixels(); i
= i + currentPower
) {
strip.setPixelColor(i, Wheel((i+j) & 255));
strip.setPixelColor(i, Wheel((i+j) & 255));
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
strip.show();
strip.show();
Copia
Copiato
Copia
Copiato
delay(wait);
delay(wait);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
/**
/**
Copia
Copiato
Copia
Copiato
* Wheel
* Input a value 0 to 255 to get a color value.
* Wheel
* The colours are a transition r - g - b - back to r.
* @source: https://github.com/adafruit/Adafruit_NeoPixel
* Input a value 0 to 255 to get a color value.
* @param byte WheelPos
*/
* The colours are a transition r - g - b - back to r.
* @source: https://github.com/adafruit/Adafruit_NeoPixel
* @param byte WheelPos
*/
uint32_t Wheel(byte WheelPos) {
uint32_t Wheel(byte WheelPos) {
Copia
Copiato
Copia
Copiato
WheelPos = 255 - WheelPos;
WheelPos = 255 - WheelPos;
Copia
Copiato
Copia
Copiato
if(WheelPos < 85) {
if(WheelPos < 85) {
Copia
Copiato
Copia
Copiato
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
if(WheelPos < 170) {
if(WheelPos < 170) {
Copia
Copiato
Copia
Copiato
WheelPos -= 85;
WheelPos -= 85;
Copia
Copiato
Copia
Copiato
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
WheelPos -= 170;
WheelPos -= 170;
Copia
Copiato
Copia
Copiato
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
uint8_t red(uint32_t c) {
uint8_t red(uint32_t c) {
Copia
Copiato
Copia
Copiato
return (c >> 8);
return (c >> 8);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
uint8_t green(uint32_t c) {
uint8_t green(uint32_t c) {
Copia
Copiato
Copia
Copiato
return (c >> 16);
return (c >> 16);
Copia
Copiato
Copia
Copiato
}
}
Copia
Copiato
Copia
Copiato
uint8_t blue(uint32_t c) {
uint8_t blue(uint32_t c) {
Copia
Copiato
Copia
Copiato
return (c);
return (c);
Copia
Copiato
Copia
Copiato
}
}
Diff salvati
Testo originale
Apri file
/* ================================================================= * LED Remote * (c) Brooke. 2016 * This file is the firmware to be upload and ran on the photon. It makes use of the particle API. * All original code is under the GPL v3 except where listed. * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ================================================================= */ /* ======================= includes ================================= */ #include <neopixel.h> // use for Build IDE // #include "neopixel.h" // use for local build /* ======================= Constances====================== */ SYSTEM_MODE(AUTOMATIC); #define PIXEL_PIN 2 #define PIXEL_COUNT 58 #define PIXEL_TYPE SK6812RGBW #define BRIGHTNESS 255 uint8_t setStripBrigtness( String brightnessValue) ; int setStripColor( String hexValue ); int currentBrightness = 0; String currentHex = ""; int loopCase = 0; Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); /** * setup -- Standard Arduino setup() function **/ void setup (){ strip.begin(); strip.show(); // Initialize all pixels to 'off' //Particle Functions for Color and Brightness Particle.function("hex", setStripColor); Particle.function("bri", setStripBrigtness); //Particle Variable to hold brightness value: Particle.variable("curBri", currentBrightness); //Particle Variable to hold color value: Particle.variable("curHex", currentHex); } /** * loop -- Standard Arduino loop() function **/ void loop (){ switch ( loopCase ) { case 1: setHex(currentHex); break; case 2: rainbowCycle(20); break; case 3: rainbow(20); } delay(20); } /** * getStripColor -- gets the HexValue input from our POST request * @param hexValue -- gets hex value string from Particle API */ int setStripColor( String hexValue ) { if(hexValue.length() == 8){ currentHex = hexValue; loopCase = 1; return 1; } else if( hexValue == "rainbow" ) { loopCase = 2; return 2; } else if ( hexValue == "rainbowCycle" ) { loopCase = 3; return 3; } else { return -1; } } /** * setStripBrightness -- Sets the LED strip color based on input of particle function setStripBrigtness * @param brightnessValue -- 0-255 brightness value for our LED strip. */ uint8_t setStripBrigtness( String brightnessValue ) { uint8_t brightnessAsInt = brightnessValue.toInt(); if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){ for (uint8_t i = 0; i < PIXEL_COUNT; i++ ){ strip.setBrightness( brightnessAsInt ); strip.show(); } currentBrightness = brightnessAsInt; return currentBrightness; } else { return 0; } } /** * convertHex -- converts hexValue into byte to be used in our array RBG > 255 * see: https://arduino.stackexchange.com/a/16446 * @param char -- gets hex value string from Particle API */ byte convertHex (const char * str){ char c = str [0] - '0'; if (c > 9) c -= 7; int result = c; c = str [1] - '0'; if (c > 9) c -= 7; return (result << 4) | c; } /** * setHex -- converts hexValue into byte to be used in our array RBG > 255 * @param hexValue HexValue to set strip to. */ char setHex( String hexValue ) { const char * hexCharArray = hexValue; byte redValue = convertHex ( & hexCharArray[0] ); byte greenValue = convertHex ( & hexCharArray[2] ); byte blueValue = convertHex ( & hexCharArray[4] ); byte whiteValue = convertHex ( & hexCharArray[6] ); for (int i = 0; i < PIXEL_COUNT; i++ ){ strip.setPixelColor(i, greenValue, redValue, blueValue, whiteValue); strip.show(); } } /** * rainbowCycle -- Cycles through colors * @source: https://github.com/adafruit/Adafruit_NeoPixel * @param wait -- mills between transition, higher is slower. Vaules 0-255 */ void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { // 5 cycles of all colors on wheel for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } /** * rainbow -- Cycles through colors * @source: https://github.com/adafruit/Adafruit_NeoPixel * @param wait -- mills between transition, higher is slower. Vaules 0-255 */ void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { for(i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); } } /** * Wheel * Input a value 0 to 255 to get a color value. * The colours are a transition r - g - b - back to r. * @source: https://github.com/adafruit/Adafruit_NeoPixel * @param byte WheelPos */ uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0); } uint8_t red(uint32_t c) { return (c >> 8); } uint8_t green(uint32_t c) { return (c >> 16); } uint8_t blue(uint32_t c) { return (c); }
Testo modificato
Apri file
/* ================================================================= * LED Remote * (c) Brooke. 2016-2020 * This file is the firmware to be upload and ran on the photon. It makes use of the particle API. * All original code is under the GPL v3 except where listed. * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA ================================================================= */ /* ======================= Includes ================================= */ #include <neopixel.h> // #include \"neopixel.h\" // use for local build /* ======================= Constances====================== */ SYSTEM_MODE(AUTOMATIC); #define PIXEL_PIN 6 #define PIXEL_COUNT 120 #define PIXEL_TYPE SK6812RGBW #define BRIGHTNESS 255 uint8_t setStripBrigtness( String brightnessValue) ; int setStripColor( String hexValue ); int currentBrightness = 0; String currentHex = \"\"; uint8_t setStripPower( String powerValue ); int currentPower = 2; int loopCase = 0; Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE); /** * setup -- Standard Arduino setup() function **/ void setup (){ strip.begin(); strip.show(); // Initialize all pixels to 'off' //Particle Functions for Color and Brightness Particle.function(\"hex\", setStripColor); Particle.function(\"bri\", setStripBrigtness); Particle.function(\"pwr\", setStripPower); //Particle Variable to hold brightness value. Shoudl return between 0 - 255 Particle.variable(\"curBri\", currentBrightness); //Particle Variable to hold color value. Should return hex or -1 for false Particle.variable(\"curHex\", currentHex); //Particle Variable to hold power value. Should always return 1 or 2. Particle.variable(\"curPwr\", currentPower); } /** * loop -- Standard Arduino loop() function **/ void loop (){ switch ( loopCase ) { case 1: setHex(currentHex); break; case 2: rainbowCycle(20); break; case 3: rainbow(20); } delay(20); } /** * getStripColor -- gets the HexValue input from our POST request * @param hexValue -- gets hex value string from Particle API */ int setStripColor( String hexValue ) { if(hexValue.length() == 8){ currentHex = hexValue; loopCase = 1; return 1; } else if( hexValue == \"rainbow\" ) { loopCase = 2; return 2; } else if ( hexValue == \"rainbowCycle\" ) { loopCase = 3; return 3; } else { return -1; } } /** * setStripBrightness -- Sets the LED strip color based on input of particle function setStripBrigtness * @param brightnessValue -- 0-255 brightness value for our LED strip. */ uint8_t setStripBrigtness( String brightnessValue ) { uint8_t brightnessAsInt = brightnessValue.toInt(); if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){ for (uint8_t i = 0; i < PIXEL_COUNT; i = i + currentPower ){ strip.setBrightness( brightnessAsInt ); } strip.show(); currentBrightness = brightnessAsInt; return currentBrightness; } else { return 0; } } /** * setStripPower -- Sets the strip power * @param powerValue -- Send 1 for all lights and send 0 for just half. */ uint8_t setStripPower( String powerValue ) { if( powerValue.toInt() == 1 ){ currentPower = 1; return 1; } else { currentPower = 2; return 0; } } /** * convertHex -- converts hexValue into byte to be used in our array RBG > 255 * see: https://arduino.stackexchange.com/a/16446 * @param char -- gets hex value string from Particle API */ byte convertHex (const char * str){ char c = str [0] - '0'; if (c > 9) c -= 7; int result = c; c = str [1] - '0'; if (c > 9) c -= 7; return (result << 4) | c; } /** * setHex -- converts hexValue into byte to be used in our array RBG > 255 * @param hexValue HexValue to set strip to. */ char setHex( String hexValue ) { const char * hexCharArray = hexValue; byte redValue = convertHex ( & hexCharArray[0] ); byte greenValue = convertHex ( & hexCharArray[2] ); byte blueValue = convertHex ( & hexCharArray[4] ); byte whiteValue = convertHex ( & hexCharArray[6] ); if( currentPower == 2 ){ for (int i = 1; i < PIXEL_COUNT; i++ ){ strip.setPixelColor(i, 0, 0, 0, 0); } } for (int i = 0; i < PIXEL_COUNT; i = i + currentPower ){ strip.setPixelColor(i, greenValue, redValue, blueValue, whiteValue); } strip.show(); } /** * rainbowCycle -- Cycles through colors * @source: https://github.com/adafruit/Adafruit_NeoPixel * @param wait -- mills between transition, higher is slower. Vaules 0-255 */ void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { // 5 cycles of all colors on wheel if( currentPower == 2 ){ for (int i = 1; i < PIXEL_COUNT; i++ ){ strip.setPixelColor(i, 0, 0, 0, 0); } } for(i=0; i< strip.numPixels(); i = i + currentPower) { strip.setPixelColor(i, Wheel(((i * 256 / PIXEL_COUNT ) + j) & 255)); } strip.show(); delay(wait); } } /** * rainbow -- Cycles through colors * @source: https://github.com/adafruit/Adafruit_NeoPixel * @param wait -- mills between transition, higher is slower. Vaules 0-255 */ void rainbow(uint8_t wait) { uint16_t i, j; for(j=0; j<256; j++) { if( currentPower == 2 ){ for (int i = 1; i < PIXEL_COUNT; i++ ){ strip.setPixelColor(i, 0, 0, 0, 0); } } for(i=0; i<strip.numPixels(); i = i + currentPower ) { strip.setPixelColor(i, Wheel((i+j) & 255)); } strip.show(); delay(wait); } } /** * Wheel * Input a value 0 to 255 to get a color value. * The colours are a transition r - g - b - back to r. * @source: https://github.com/adafruit/Adafruit_NeoPixel * @param byte WheelPos */ uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0); } if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0); } WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0); } uint8_t red(uint32_t c) { return (c >> 8); } uint8_t green(uint32_t c) { return (c >> 16); } uint8_t blue(uint32_t c) { return (c); }
Trovare la differenza