// Date: 03/12/2025
// Experiment No: 07
// Name: Rajaram Parida
// Redg: 2241016203
// Section: 224101028
// Objective 5
#include <Adafruit_NeoPixel.h>
#define LED_PIN 7
#define NUM_LEDS 30
Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show();
}
void loop() {
rainbowCycle(5);
colorFade(255, 0, 0, 0, 0, 255, 5);
colorChase(strip.Color(0, 255, 0), 50);
colorChase(strip.Color(255, 0, 255), 50);
colorChase(strip.Color(0, 255, 255), 50);
}
void rainbowCycle(uint8_t wait) {
for(long first = 0; first < 256 * 5; first++) {
for(int i = 0; i < NUM_LEDS; i++) {
int pixel = (i * 256 / NUM_LEDS + first) & 255;
strip.setPixelColor(i, Wheel(pixel));
}
strip.show();
delay(wait);
}
}
void colorFade(byte r1, byte g1, byte b1, byte r2, byte g2, byte b2, int speed) {
for(int i = 0; i <= 255; i++) {
int r = map(i, 0, 255, r1, r2);
int g = map(i, 0, 255, g1, g2);
int b = map(i, 0, 255, b1, b2);
for(int p = 0; p < NUM_LEDS; p++) strip.setPixelColor(p, strip.Color(r, g, b));
strip.show();
delay(speed);
}
}
void colorChase(uint32_t c, int wait) {
for(int i = 0; i < NUM_LEDS; i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
strip.setPixelColor(i, 0);
}
}
uint32_t Wheel(byte p) {
p = 255 - p;
if(p < 85) return strip.Color(255 - p * 3, 0, p * 3);
if(p < 170) p -= 85;
else p -= 170;
return (p < 85) ? strip.Color(0, p * 3, 255 - p * 3) : strip.Color(p * 3, 255 - p * 3, 0);
}