Diff
checker
텍스트
텍스트
이미지
문서
Excel
폴더
Legal
Enterprise
데스크톱
요금제
로그인
데스크톱 앱 다운로드
텍스트 비교
두 텍스트 파일의 차이점을 찾아보세요
도구
기록
실시간 편집
공백 변경 숨기기
변경 없는 행 숨기기
줄바꿈 비활성화
레이아웃
나란히 보기
합쳐 보기
비교 단위
스마트
단어
글자
텍스트 스타일
모양 변경
구문 강조
언어 선택
제외
텍스트 변환
첫 변경으로
수정
Diffchecker Desktop
가장 안전하게 Diffchecker를 사용하는 방법. 데스크톱 앱을 사용하면 비교 데이터가 외부로 전송되지 않습니다!
데스크톱 앱 받기
LED_Remote
생성일
4년 전
비교 결과 만료 없음
초기화
내보내기
공유
설명
28 삭제
행
총
삭제
글자
총
삭제
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
227 행
복사
397 추가
행
총
추가
글자
총
추가
이 기능을 계속 사용하려면 업그레이드해 주세요
Diff
checker
Pro
요금제 보기
533 행
복사
/* =================================================================
/* =================================================================
복사
복사됨
복사
복사됨
* LED Remote
* LED Remote
복사
복사됨
복사
복사됨
* (c) Brooke. 2016
* (c) Brooke. 2016
-2020
복사
복사됨
복사
복사됨
* 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.
복사
복사됨
복사
복사됨
* All original code is under the GPL v3 except where listed.
* All original code is under the GPL v3 except where listed.
복사
복사됨
복사
복사됨
* This program is free software; you can redistribute it and/or modify
* 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
* it under the terms of the GNU General Public License as published by
복사
복사됨
복사
복사됨
* the Free Software Foundation; either version 3 of the License, or
* the Free Software Foundation; either version 3 of the License, or
복사
복사됨
복사
복사됨
* (at your option) any later version.
* (at your option) any later version.
복사
복사됨
복사
복사됨
* This program is distributed in the hope that it will be useful,
* This program is distributed in the hope that it will be useful,
복사
복사됨
복사
복사됨
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* but WITHOUT ANY WARRANTY; without even the implied warranty of
복사
복사됨
복사
복사됨
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
복사
복사됨
복사
복사됨
* GNU General Public License for more details.
* GNU General Public License for more details.
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
* You should have received a copy of the GNU General Public License
* You should have received a copy of the GNU General Public License
복사
복사됨
복사
복사됨
* along with this program; if not, write to the Free Software
* along with this program; if not, write to the Free Software
복사
복사됨
복사
복사됨
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301
USA
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301
USA
================================================================= */
================================================================= */
복사
복사됨
복사
복사됨
/* =======================
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====================== */
복사
복사됨
복사
복사됨
SYSTEM_MODE(AUTOMATIC);
SYSTEM_MODE(AUTOMATIC);
복사
복사됨
복사
복사됨
#define PIXEL_PIN
2
#define PIXEL_COUNT
58
#define PIXEL_PIN
6
#define PIXEL_COUNT
120
#define PIXEL_TYPE SK6812RGBW
#define PIXEL_TYPE SK6812RGBW
복사
복사됨
복사
복사됨
#define BRIGHTNESS 255
#define BRIGHTNESS 255
복사
복사됨
복사
복사됨
uint8_t setStripBrigtness( String brightnessValue) ;
uint8_t setStripBrigtness( String brightnessValue) ;
복사
복사됨
복사
복사됨
int
setStripColor( String hexValue );
int
setStripColor( String hexValue );
int currentBrightness = 0;
int currentBrightness = 0;
복사
복사됨
복사
복사됨
String currentHex =
"";
String currentHex =
\"\";
uint8_t setStripPower( String powerValue );
int currentPower = 2;
int loopCase = 0;
int loopCase = 0;
복사
복사됨
복사
복사됨
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
복사
복사됨
복사
복사됨
/**
/**
* setup -- Standard Arduino setup() function
* setup -- Standard Arduino setup() function
복사
복사됨
복사
복사됨
**/
**/
복사
복사됨
복사
복사됨
void setup (){
void setup (){
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
strip.begin();
strip.begin();
복사
복사됨
복사
복사됨
strip.show(); // Initialize all pixels to 'off'
strip.show(); // Initialize all pixels to 'off'
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
//Particle Functions for Color and Brightness
//Particle Functions for Color and Brightness
복사
복사됨
복사
복사됨
Particle.function(
"hex
", setStripColor);
Particle.function(
"bri
", setStripBrigtness);
Particle.function(
\
"hex
\
", setStripColor);
Particle.function(
\
"bri
\
", setStripBrigtness);
Particle.function(\"pwr\", setStripPower);
복사
복사됨
복사
복사됨
//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);
복사
복사됨
복사
복사됨
//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);
복사
복사됨
복사
복사됨
}
//Particle Variable to hold power value. Should always return 1 or 2.
Particle.variable(\"curPwr\", currentPower);
}
복사
복사됨
복사
복사됨
/**
/**
복사
복사됨
복사
복사됨
* loop -- Standard Arduino loop() function
**/
* loop -- Standard Arduino loop() function
**/
void loop (){
void loop (){
복사
복사됨
복사
복사됨
switch ( loopCase ) {
switch ( loopCase ) {
복사
복사됨
복사
복사됨
case 1:
case 1:
복사
복사됨
복사
복사됨
setHex(currentHex);
setHex(currentHex);
복사
복사됨
복사
복사됨
break;
break;
복사
복사됨
복사
복사됨
case 2:
case 2:
복사
복사됨
복사
복사됨
rainbowCycle(20);
rainbowCycle(20);
복사
복사됨
복사
복사됨
break;
break;
복사
복사됨
복사
복사됨
case 3:
case 3:
복사
복사됨
복사
복사됨
rainbow(20);
rainbow(20);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
delay(20);
delay(20);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
/**
/**
복사
복사됨
복사
복사됨
* 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 ) {
복사
복사됨
복사
복사됨
if(hexValue.length() == 8){
if(hexValue.length() == 8){
복사
복사됨
복사
복사됨
currentHex = hexValue;
currentHex = hexValue;
복사
복사됨
복사
복사됨
loopCase = 1;
loopCase = 1;
복사
복사됨
복사
복사됨
return 1;
return 1;
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
else if( hexValue ==
"rainbow
" ) {
else if( hexValue ==
\
"rainbow
\
" ) {
loopCase = 2;
loopCase = 2;
복사
복사됨
복사
복사됨
return 2;
return 2;
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
else if ( hexValue ==
"rainbowCycle
" ) {
else if ( hexValue ==
\
"rainbowCycle
\
" ) {
loopCase = 3;
loopCase = 3;
복사
복사됨
복사
복사됨
return 3;
return 3;
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
else {
else {
복사
복사됨
복사
복사됨
return -1;
return -1;
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
/**
/**
* 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
복사
복사됨
복사
복사됨
* @param brightnessValue -- 0-255 brightness value for our LED strip.
* @param brightnessValue -- 0-255 brightness value for our LED strip.
복사
복사됨
복사
복사됨
*/
*/
복사
복사됨
복사
복사됨
uint8_t setStripBrigtness( String brightnessValue ) {
uint8_t setStripBrigtness( String brightnessValue ) {
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
uint8_t brightnessAsInt = brightnessValue.toInt();
uint8_t brightnessAsInt = brightnessValue.toInt();
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){
if( ( brightnessAsInt <= 255 ) && ( brightnessValue.length() <= 3 ) ){
복사
복사됨
복사
복사됨
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 );
복사
복사됨
복사
복사됨
strip.show();
}
}
복사
복사됨
복사
복사됨
strip.show();
currentBrightness = brightnessAsInt;
currentBrightness = brightnessAsInt;
복사
복사됨
복사
복사됨
return currentBrightness;
return currentBrightness;
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
else {
else {
복사
복사됨
복사
복사됨
return 0;
return 0;
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
/**
/**
복사
복사됨
복사
복사됨
* 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){
복사
복사됨
복사
복사됨
char c = str [0] - '0';
char c = str [0] - '0';
복사
복사됨
복사
복사됨
if (c > 9)
if (c > 9)
복사
복사됨
복사
복사됨
c -= 7;
c -= 7;
복사
복사됨
복사
복사됨
int result = c;
int result = c;
복사
복사됨
복사
복사됨
c = str [1] - '0';
c = str [1] - '0';
복사
복사됨
복사
복사됨
if (c > 9)
if (c > 9)
복사
복사됨
복사
복사됨
c -= 7;
c -= 7;
복사
복사됨
복사
복사됨
return (result << 4) | c;
return (result << 4) | c;
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
/**
/**
복사
복사됨
복사
복사됨
* 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.
*/
복사
복사됨
복사
복사됨
char setHex( String hexValue ) {
char setHex( String hexValue ) {
복사
복사됨
복사
복사됨
const char * hexCharArray = hexValue;
const char * hexCharArray = hexValue;
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
byte redValue = convertHex ( & hexCharArray[0] );
byte redValue = convertHex ( & hexCharArray[0] );
복사
복사됨
복사
복사됨
byte greenValue = convertHex ( & hexCharArray[2] );
byte greenValue = convertHex ( & hexCharArray[2] );
복사
복사됨
복사
복사됨
byte blueValue = convertHex ( & hexCharArray[4] );
byte blueValue = convertHex ( & hexCharArray[4] );
복사
복사됨
복사
복사됨
byte whiteValue = convertHex ( & hexCharArray[6] );
byte whiteValue = convertHex ( & hexCharArray[6] );
복사
복사됨
복사
복사됨
복사
복사됨
복사
복사됨
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);
복사
복사됨
복사
복사됨
strip.show();
}
}
복사
복사됨
복사
복사됨
strip.show();
}
}
복사
복사됨
복사
복사됨
/**
/**
복사
복사됨
복사
복사됨
* 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) {
복사
복사됨
복사
복사됨
uint16_t i, j;
uint16_t i, j;
복사
복사됨
복사
복사됨
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
복사
복사됨
복사
복사됨
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));
}
}
복사
복사됨
복사
복사됨
strip.show();
strip.show();
복사
복사됨
복사
복사됨
delay(wait);
delay(wait);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
/**
/**
복사
복사됨
복사
복사됨
* 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) {
복사
복사됨
복사
복사됨
uint16_t i, j;
uint16_t i, j;
복사
복사됨
복사
복사됨
for(j=0; j<256; j++) {
for(j=0; j<256; j++) {
복사
복사됨
복사
복사됨
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));
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
strip.show();
strip.show();
복사
복사됨
복사
복사됨
delay(wait);
delay(wait);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
/**
/**
복사
복사됨
복사
복사됨
* 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) {
복사
복사됨
복사
복사됨
WheelPos = 255 - WheelPos;
WheelPos = 255 - WheelPos;
복사
복사됨
복사
복사됨
if(WheelPos < 85) {
if(WheelPos < 85) {
복사
복사됨
복사
복사됨
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3,0);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
if(WheelPos < 170) {
if(WheelPos < 170) {
복사
복사됨
복사
복사됨
WheelPos -= 85;
WheelPos -= 85;
복사
복사됨
복사
복사됨
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3,0);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
WheelPos -= 170;
WheelPos -= 170;
복사
복사됨
복사
복사됨
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0,0);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
uint8_t red(uint32_t c) {
uint8_t red(uint32_t c) {
복사
복사됨
복사
복사됨
return (c >> 8);
return (c >> 8);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
uint8_t green(uint32_t c) {
uint8_t green(uint32_t c) {
복사
복사됨
복사
복사됨
return (c >> 16);
return (c >> 16);
복사
복사됨
복사
복사됨
}
}
복사
복사됨
복사
복사됨
uint8_t blue(uint32_t c) {
uint8_t blue(uint32_t c) {
복사
복사됨
복사
복사됨
return (c);
return (c);
복사
복사됨
복사
복사됨
}
}
저장된 비교 결과
원본
파일 열기
/* ================================================================= * 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); }
수정본
파일 열기
/* ================================================================= * 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); }
비교하기