Skip to content

Add function to accept color as array. #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions EasyNeoPixels.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,10 @@ void writeEasyNeoPixel(int num, int r, int g, int b) {
easyNeoPixels.setPixelColor(num, easyNeoPixels.Color(r,g,b));
easyNeoPixels.show();
}

// set neopixels with color in array format
// meant to be used with array for color eg: int red[3] = {255, 0, 0}, int green[3] = {0, 255, 0}, int blue[3] = {0, 0, 255}, etc.
void writeEasyNeoPixel(int num, int color[]) {
easyNeoPixels.setPixelColor(num, color[0], color[1], color[2]);
easyNeoPixels.show();
}
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ It's as easy as:
setupEasyNeoPixels(13, 1); // attached to pin 13, 1 neopixel long
writeEasyNeoPixel(0, HIGH); // turn on the first neopixel
writeEasyNeoPixel(0, 255, 0, 255); // make the first neopixel purple (red + blue)


int green[3] = {0, 255, 0}; // define array for color
writeEasyNeoPixel(0, green); // make the first neopixel the color of the array
```

## Examples
Expand Down
35 changes: 35 additions & 0 deletions examples/colorSweep/colorSweep.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <EasyNeoPixels.h>

int pixelPin = 3;
int numPixels = 16;
int timer = 30;

int green[3] = {0, 255, 0};

void setup() {
setupEasyNeoPixels(pixelPin, numPixels);
}

void loop() {
for (int i = 0; i < numPixels; i++) {
writeEasyNeoPixel(i, green);
//delay(timer);
writeEasyNeoPixel(i + 1, green);
//delay(timer);
writeEasyNeoPixel(i + 2, green);
delay(timer);
writeEasyNeoPixel(i, 0, 0, 0);
delay(timer*2);
}

for (int j = numPixels; j > 0; j--) {
writeEasyNeoPixel(j, green);
//delay(timer);
writeEasyNeoPixel(j - 1, green);
//delay(timer);
writeEasyNeoPixel(j - 2, green);
delay(timer);
writeEasyNeoPixel(j, 0, 0, 0);
delay(timer*2);
}
}