#include <Adafruit_NeoPixel.h>
#define PIN 9
#define NUMPIXELS 12
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
const uint32_t RED = pixels.Color(225, 0, 0);
const uint32_t COLOUR = RED;
const int MIN_BRIGHTNESS = 140;
const int MAX_BRIGHTNESS = 200;
const int BRIGHTNESS_STEP = 1;
const int CHANGE_DELAY = 100;
int currentBrightness = MIN_BRIGHTNESS;
int direction = 1;
void setup() {
// put your setup code here, to run once:
pixels.begin();
}
void setAllPixels(int brightness) {
pixels.fill(COLOUR, 0, pixels.numPixels());
pixels.setBrightness(brightness);
pixels.show();
}
void setDirectionBrighter() {
direction = 1;
}
void setDirectionDarker() {
direction = -1;
}
void loop() {
setAllPixels(currentBrightness);
if (currentBrightness > MAX_BRIGHTNESS) {
setDirectionDarker();
}
if (currentBrightness < MIN_BRIGHTNESS) {
setDirectionBrighter();
}
currentBrightness = currentBrightness + (BRIGHTNESS_STEP * direction);
delay(CHANGE_DELAY);
}