// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>
#define PIXEL_PIN D2
#define PIXEL_COUNT 150
#define PIXEL_TYPE WS2812B
Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
// Prototypes for local build, ok to leave in for Build IDE
void rainbow(uint8_t wait);
uint32_t Wheel(byte WheelPos);
int distance = A0;
int brightness = 0;
int fadeAmount = -5;
int waitTime = 100;
void setup() {
pinMode(distance, INPUT);
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
int dist = analogRead(distance);
Serial.print("distance is:"); Serial.println(dist); Serial.println();
if (dist > 670){
Serial.print("made into loop with brightness:"); Serial.println(brightness);
rainbow(waitTime);
if (brightness < 5 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
brightness = brightness + fadeAmount;
} else {
rainbow(waitTime);
}
delay(waitTime);
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(i=0; i<strip.numPixels(); i++) {
uint32_t c = strip.Color(brightness, brightness, brightness);
strip.setPixelColor(i, c);
}
strip.show();
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .