Last active
July 16, 2016 17:30
-
-
Save fenihel/835719d8f4af0d545242898bcb6a86c4 to your computer and use it in GitHub Desktop.
Neopixel Pulse
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_NeoPixel.h> | |
// LED connected to digital pin 6 | |
int dataPin = 6; | |
#define NUMPIXELS 15 | |
#define MAXIMUM_BRIGHTNESS 255 | |
#define MEDIUM_BRIGHTNESS 130 | |
#define LOW_BRIGHTNESS 100 | |
int maxBrightness = 255; | |
int minBrightness = 80; | |
boolean isPulsing = true; | |
Adafruit_NeoPixel pixel = Adafruit_NeoPixel(NUMPIXELS, dataPin); | |
void setup() { | |
Serial.begin(115200); | |
pixel.begin(); // This initializes the NeoPixel library. | |
setLightsToColor(0, 100, 255); | |
// turn off neopixel | |
turnOffLights(); | |
} | |
void loop() { | |
if (isPulsing) { | |
pulse(); | |
} | |
} | |
void pulse() { | |
// fade in | |
for (int x = minBrightness; x < MAXIMUM_BRIGHTNESS; x++) { | |
setLightsToBrightness(x); | |
} | |
// fade out | |
for (int x = MAXIMUM_BRIGHTNESS; x >= minBrightness; x--) { | |
setLightsToBrightness(x); | |
} | |
} | |
void solid() { | |
setLightsToBrightness(maxBrightness); | |
} | |
void turnOffLights() { | |
setLightsToBrightness(0); | |
} | |
void setLightsToColor(int red, int green, int blue) { | |
for (uint8_t i = 0; i < NUMPIXELS; i++) { | |
pixel.setPixelColor(i, pixel.Color(red, green, blue)); | |
} | |
} | |
void setLightsToBrightness(int brightness) { | |
pixel.setBrightness(brightness); | |
setLightsToColor(0, 100, 255); | |
pixel.show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment