Diff
checker
Texto
Texto
Imágenes
Documentos
Excel
Carpetas
Legal
Enterprise
Aplicación de escritorio
Precios
Iniciar sesión
Descargar Diffchecker Desktop
Comparar texto
Encuentra la diferencia entre dos archivos de texto
Herramientas
Historial
Editor live
Ocultar espacios en blanco
Ocultar sin cambios
Sin ajuste de línea
Vista
Dividido
Unificado
Nivel de detalle
Inteligente
Palabra
Letra
Estilos de texto
Cambiar apariencia
Resaltado de sintaxis
Elegir sintaxis
Ignorar
Transformar texto
Ir al primer cambio
Editar entrada
Diffchecker Desktop
La forma más segura de usar Diffchecker. ¡Obtén la app de Diffchecker Desktop: tus diffs nunca salen de tu computadora!
Obtener Desktop
LED_Remote
Creado
hace 4 años
El diff nunca expira
Borrar
Exportar
Compartir
Explicar
28 eliminaciones
Líneas
Total
Eliminado
Caracteres
Total
Eliminado
Para continuar usando esta función, actualice a
Diff
checker
Pro
Ver precios
227 líneas
Copiar todo
397 adiciones
Líneas
Total
Añadido
Caracteres
Total
Añadido
Para continuar usando esta función, actualice a
Diff
checker
Pro
Ver precios
533 líneas
Copiar todo
/* =================================================================
/* =================================================================
Copiar
Copiado
Copiar
Copiado
* LED Remote
* LED Remote
Copiar
Copiado
Copiar
Copiado
* (c) Brooke. 2016
* (c) Brooke. 2016
-2020
Copiar
Copiado
Copiar
Copiado
* 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.
Copiar
Copiado
Copiar
Copiado
* All original code is under the GPL v3 except where listed.
* All original code is under the GPL v3 except where listed.
Copiar
Copiado
Copiar
Copiado
* This program is free software; you can redistribute it and/or modify
* This program is free software; you can redistribute it and/or modify
Copiar
Copiado
Copiar
Copiado
* 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
Copiar
Copiado
Copiar
Copiado
* the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or
Copiar
Copiado
Copiar
Copiado
* (at your option) any later version.
* (at your option) any later version.
Copiar
Copiado
Copiar
Copiado
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
Copiar
Copiado
Copiar
Copiado
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
Copiar
Copiado
Copiar
Copiado
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Copiar
Copiado
Copiar
Copiado
* GNU General Public License for more details.
* GNU General Public License for more details.
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
Copiar
Copiado
Copiar
Copiado
* along with this program; if not, write to the Free Software
* along with this program; if not, write to the Free Software
Copiar
Copiado
Copiar
Copiado
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301
USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301
USA
================================================================= */
================================================================= */
Copiar
Copiado
Copiar
Copiado
/* =======================
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====================== */
Copiar
Copiado
Copiar
Copiado
SYSTEM_MODE(AUTOMATIC);
SYSTEM_MODE(AUTOMATIC);
Copiar
Copiado
Copiar
Copiado
#define PIXEL_PIN
2
#define PIXEL_COUNT
58
#define PIXEL_PIN
6
#define PIXEL_COUNT
120
#define PIXEL_TYPE SK6812RGBW
#define PIXEL_TYPE SK6812RGBW
Copiar
Copiado
Copiar
Copiado
#define BRIGHTNESS 255
#define BRIGHTNESS 255
Copiar
Copiado
Copiar
Copiado
uint8_t setStripBrigtness( String brightnessValue) ;
uint8_t setStripBrigtness( String brightnessValue) ;
Copiar
Copiado
Copiar
Copiado
int
setStripColor( String hexValue );
int
setStripColor( String hexValue );
int currentBrightness = 0;
int currentBrightness = 0;
Copiar
Copiado
Copiar
Copiado
String currentHex =
"";
String currentHex =
\"\";
uint8_t setStripPower( String powerValue );
int currentPower = 2;
int loopCase = 0;
int loopCase = 0;
Copiar
Copiado
Copiar
Copiado
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
Copiar
Copiado
Copiar
Copiado
/**
/**
* setup -- Standard Arduino setup() function
* setup -- Standard Arduino setup() function
Copiar
Copiado
Copiar
Copiado
**/
**/
Copiar
Copiado
Copiar
Copiado
void setup (){
void setup (){
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
strip.begin();
strip.begin();
Copiar
Copiado
Copiar
Copiado
strip.show(); // Initialize all pixels to 'off'
strip.show(); // Initialize all pixels to 'off'
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
//Particle Functions for Color and Brightness
//Particle Functions for Color and Brightness
Copiar
Copiado
Copiar
Copiado
Particle.function(
"hex
", setStripColor);
Particle.function(
"bri
", setStripBrigtness);
Particle.function(
\
"hex
\
", setStripColor);
Particle.function(
\
"bri
\
", setStripBrigtness);
Particle.function(\"pwr\", setStripPower);
Copiar
Copiado
Copiar
Copiado
//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);
Copiar
Copiado
Copiar
Copiado
//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);
Copiar
Copiado
Copiar
Copiado
}
//Particle Variable to hold power value. Should always return 1 or 2.
Particle.variable(\"curPwr\", currentPower);
}
Copiar
Copiado
Copiar
Copiado
/**
/**
Copiar
Copiado
Copiar
Copiado
* loop -- Standard Arduino loop() function
**/
* loop -- Standard Arduino loop() function
**/
void loop (){
void loop (){
Copiar
Copiado
Copiar
Copiado
switch ( loopCase ) {
switch ( loopCase ) {
Copiar
Copiado
Copiar
Copiado
case 1:
case 1:
Copiar
Copiado
Copiar
Copiado
setHex(currentHex);
setHex(currentHex);
Copiar
Copiado
Copiar
Copiado
break;
break;
Copiar
Copiado
Copiar
Copiado
case 2:
case 2:
Copiar
Copiado
Copiar
Copiado
rainbowCycle(20);
rainbowCycle(20);
Copiar
Copiado
Copiar
Copiado
break;
break;
Copiar
Copiado
Copiar
Copiado
case 3:
case 3:
Copiar
Copiado
Copiar
Copiado
rainbow(20);
rainbow(20);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
delay(20);
delay(20);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
/**
/**
Copiar
Copiado
Copiar
Copiado
* 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 ) {
Copiar
Copiado
Copiar
Copiado
if(hexValue.length() == 8){
if(hexValue.length() == 8){
Copiar
Copiado
Copiar
Copiado
currentHex = hexValue;
currentHex = hexValue;
Copiar
Copiado
Copiar
Copiado
loopCase = 1;
loopCase = 1;
Copiar
Copiado
Copiar
Copiado
return 1;
return 1;
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
else if( hexValue ==
"rainbow
" ) {
else if( hexValue ==
\
"rainbow
\
" ) {
loopCase = 2;
loopCase = 2;
Copiar
Copiado
Copiar
Copiado
return 2;
return 2;
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
else if ( hexValue ==
"rainbowCycle
" ) {
else if ( hexValue ==
\
"rainbowCycle
\
" ) {
loopCase = 3;
loopCase = 3;
Copiar
Copiado
Copiar
Copiado
return 3;
return 3;
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
else {
else {
Copiar
Copiado
Copiar
Copiado
return -1;
return -1;
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
/**
/**
* 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
Copiar
Copiado
Copiar
Copiado
* @param brightnessValue -- 0-255 brightness value for our LED strip.
* @param brightnessValue -- 0-255 brightness value for our LED strip.
Copiar
Copiado
Copiar
Copiado
*/
*/
Copiar
Copiado
Copiar
Copiado
uint8_t setStripBrigtness( String brightnessValue ) {
uint8_t setStripBrigtness( String brightnessValue ) {
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
uint8_t brightnessAsInt = brightnessValue.toInt();
uint8_t brightnessAsInt = brightnessValue.toInt();
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){
if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){
Copiar
Copiado
Copiar
Copiado
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 );
Copiar
Copiado
Copiar
Copiado
strip.show();
}
}
Copiar
Copiado
Copiar
Copiado
strip.show();
currentBrightness = brightnessAsInt;
currentBrightness = brightnessAsInt;
Copiar
Copiado
Copiar
Copiado
return currentBrightness;
return currentBrightness;
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
else {
else {
Copiar
Copiado
Copiar
Copiado
return 0;
return 0;
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
/**
/**
Copiar
Copiado
Copiar
Copiado
* 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){
Copiar
Copiado
Copiar
Copiado
char c = str [0] - '0';
char c = str [0] - '0';
Copiar
Copiado
Copiar
Copiado
if (c > 9)
if (c > 9)
Copiar
Copiado
Copiar
Copiado
c -= 7;
c -= 7;
Copiar
Copiado
Copiar
Copiado
int result = c;
int result = c;
Copiar
Copiado
Copiar
Copiado
c = str [1] - '0';
c = str [1] - '0';
Copiar
Copiado
Copiar
Copiado
if (c > 9)
if (c > 9)
Copiar
Copiado
Copiar
Copiado
c -= 7;
c -= 7;
Copiar
Copiado
Copiar
Copiado
return (result << 4) | c;
return (result << 4) | c;
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
/**
/**
Copiar
Copiado
Copiar
Copiado
* 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.
*/
Copiar
Copiado
Copiar
Copiado
char setHex( String hexValue ) {
char setHex( String hexValue ) {
Copiar
Copiado
Copiar
Copiado
const char * hexCharArray = hexValue;
const char * hexCharArray = hexValue;
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
byte redValue = convertHex ( & hexCharArray[0] );
byte redValue = convertHex ( & hexCharArray[0] );
Copiar
Copiado
Copiar
Copiado
byte greenValue = convertHex ( & hexCharArray[2] );
byte greenValue = convertHex ( & hexCharArray[2] );
Copiar
Copiado
Copiar
Copiado
byte blueValue = convertHex ( & hexCharArray[4] );
byte blueValue = convertHex ( & hexCharArray[4] );
Copiar
Copiado
Copiar
Copiado
byte whiteValue = convertHex ( & hexCharArray[6] );
byte whiteValue = convertHex ( & hexCharArray[6] );
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
Copiar
Copiado
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);
Copiar
Copiado
Copiar
Copiado
strip.show();
}
}
Copiar
Copiado
Copiar
Copiado
strip.show();
}
}
Copiar
Copiado
Copiar
Copiado
/**
/**
Copiar
Copiado
Copiar
Copiado
* 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) {
Copiar
Copiado
Copiar
Copiado
uint16_t i, j;
uint16_t i, j;
Copiar
Copiado
Copiar
Copiado
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
Copiar
Copiado
Copiar
Copiado
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));
}
}
Copiar
Copiado
Copiar
Copiado
strip.show();
strip.show();
Copiar
Copiado
Copiar
Copiado
delay(wait);
delay(wait);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
/**
/**
Copiar
Copiado
Copiar
Copiado
* 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) {
Copiar
Copiado
Copiar
Copiado
uint16_t i, j;
uint16_t i, j;
Copiar
Copiado
Copiar
Copiado
for(j=0; j<256; j++) {
for(j=0; j<256; j++) {
Copiar
Copiado
Copiar
Copiado
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));
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
strip.show();
strip.show();
Copiar
Copiado
Copiar
Copiado
delay(wait);
delay(wait);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
/**
/**
Copiar
Copiado
Copiar
Copiado
* 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) {
Copiar
Copiado
Copiar
Copiado
WheelPos = 255 - WheelPos;
WheelPos = 255 - WheelPos;
Copiar
Copiado
Copiar
Copiado
if(WheelPos < 85) {
if(WheelPos < 85) {
Copiar
Copiado
Copiar
Copiado
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
if(WheelPos < 170) {
if(WheelPos < 170) {
Copiar
Copiado
Copiar
Copiado
WheelPos -= 85;
WheelPos -= 85;
Copiar
Copiado
Copiar
Copiado
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
WheelPos -= 170;
WheelPos -= 170;
Copiar
Copiado
Copiar
Copiado
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
uint8_t red(uint32_t c) {
uint8_t red(uint32_t c) {
Copiar
Copiado
Copiar
Copiado
return (c >> 8);
return (c >> 8);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
uint8_t green(uint32_t c) {
uint8_t green(uint32_t c) {
Copiar
Copiado
Copiar
Copiado
return (c >> 16);
return (c >> 16);
Copiar
Copiado
Copiar
Copiado
}
}
Copiar
Copiado
Copiar
Copiado
uint8_t blue(uint32_t c) {
uint8_t blue(uint32_t c) {
Copiar
Copiado
Copiar
Copiado
return (c);
return (c);
Copiar
Copiado
Copiar
Copiado
}
}
Diferencias guardadas
Texto original
Abrir archivo
/* ================================================================= * 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); }
Texto modificado
Abrir archivo
/* ================================================================= * 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); }
Encontrar la diferencia