#include <Adafruit_NeoPixel.h>//
#define PIN 26
#define LEDS 16
Adafruit_NeoPixel strip(LEDS, PIN, NEO_GRB + NEO_KHZ800);
int PIRstate = LOW;
void setup() {
pinMode(14, INPUT);
strip.begin();
strip.show(); // All pixels OFF
}
void loop()
{
PIRstate = digitalRead(14);
if (PIRstate == HIGH)
{
//Simulate motion
colorWipe(strip.Color(255, 215, 0), 100); //Yellow
colorWipe(strip.Color(255, 0, 127), 100); //Pink
colorWipe(strip.Color(0, 191, 230), 100); //Sky blue
rainbowCycle(1000); //Rainbow effect
//tbh used ChatGPT for RainbowCycle since it looked cool!
}
}
//Circle colour
void colorWipe(int color, int Delay){
for(int i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, color);
strip.show();
delay(Delay);
}
}
// Cycle through the colors of the rainbow
void rainbowCycle(int Delay) {
for(int j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(int i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
delay(Delay);
}
}
// Generate a color based on a position on the color wheel (0 - 255)
int Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}