Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #define PIN 4
- #define NUM_LIGHTS 50
- // =========================================================================================================
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LIGHTS, PIN, NEO_GRB + NEO_KHZ800);
- int currentColorValueRed;
- int currentColorValueGreen;
- int currentColorValueBlue;
- int colorData;
- int brightnessValue;
- int currentMode;
- int counter = 1;
- int colorValueRed;
- int colorValueGreen;
- int colorValueBlue;
- int fadeValue;
- int buttonState = 0;
- int potPinValue;
- int delayValue;
- int speedValue;
- int ColorPotPin = A3;
- int brightnessPotPin = A4;
- int modeButtonPin = 2;
- // =========================================================================================================
- void setup() {
- pinMode(ColorPotPin, INPUT);
- pinMode(brightnessPotPin, INPUT);
- pinMode(modeButtonPin, INPUT);
- pinMode(13, OUTPUT);
- Serial.begin(9600);
- strip.begin();
- strip.show(); // Initialize all pixels to 'off'
- }
- // =========================================================================================================
- void loop() {
- int brightnessPot = map(analogRead(brightnessPotPin), 0, 1024, 1, 255);
- float brightnessValue = brightnessPot / 255.0;
- // =========================================================================================================
- if (potPinValue <= 42.5) {
- currentColorValueRed = 255;
- currentColorValueGreen = potPinValue * 6;
- currentColorValueBlue = 0;
- }
- if ((potPinValue > 42.5) && (potPinValue <= 85)) {
- currentColorValueRed = 255 - (potPinValue - 43) * 6;
- currentColorValueGreen = 255;
- currentColorValueBlue = 0;
- }
- if ((potPinValue > 85) && (potPinValue <= 127.5)) {
- currentColorValueRed = 0;
- currentColorValueGreen = 255;
- currentColorValueBlue = (potPinValue - 85) * 6; }
- if ((potPinValue > 127.5) && (potPinValue <= 170)) {
- currentColorValueRed = 0;
- currentColorValueGreen = 255 - (potPinValue - 127.5) * 6;
- currentColorValueBlue = 255;
- }
- if ((potPinValue > 170) && (potPinValue <= 212.5)) {
- currentColorValueRed = (potPinValue - 170) * 6;
- currentColorValueGreen = 0;
- currentColorValueBlue = 255;
- }
- if ((potPinValue > 212.5) && (potPinValue <= 255)) {
- currentColorValueRed = 255;
- currentColorValueGreen = 0;
- currentColorValueBlue = 255 - (potPinValue - 212.5) * 6;
- }
- // =========================================================================================================
- if (fadeValue <= 42.5) {
- colorValueRed = 255;
- colorValueGreen = fadeValue * 6;
- colorValueBlue = 0;
- }
- if ((fadeValue > 42.5) && (fadeValue <= 85)) {
- colorValueRed = 255 - (fadeValue - 43) * 6;
- colorValueGreen = 255;
- colorValueBlue = 0;
- }
- if ((fadeValue > 85) && (fadeValue <= 127.5)) {
- colorValueRed = 0;
- colorValueGreen = 255;
- colorValueBlue = (fadeValue - 85) * 6; }
- if ((fadeValue > 127.5) && (fadeValue <= 170)) {
- colorValueRed = 0;
- colorValueGreen = 255 - (fadeValue - 127.5) * 6;
- colorValueBlue = 255;
- }
- if ((fadeValue > 170) && (fadeValue<= 212.5)) {
- colorValueRed = (fadeValue - 170) * 6;
- colorValueGreen = 0;
- colorValueBlue = 255;
- }
- if ((fadeValue > 212.5) && (fadeValue <= 255)) {
- colorValueRed = 255;
- colorValueGreen = 0;
- colorValueBlue = 255 - (fadeValue - 212.5) * 6;
- }
- // =========================================================================================================
- if (fadeValue == 256) {
- fadeValue = 0;
- }
- if (fadeValue == 0) {
- fadeValue = 1;
- }
- // =========================================================================================================
- buttonState = digitalRead(2);
- if (buttonState == HIGH) {
- counter++;
- delay(1000);
- if (counter == 6) {
- counter = 1;
- }
- Serial.println(counter);
- }
- // =========================================================================================================
- delayValue = map(analogRead(ColorPotPin), 0, 1024, 500, 5);
- // =========================================================================================================
- if (counter == 1) {
- potPinValue = map(analogRead(ColorPotPin), 0, 1024, 3, 255);
- uint32_t high = strip.Color(currentColorValueRed, currentColorValueGreen, currentColorValueBlue);
- strip.setBrightness(brightnessPot);
- for( int i = 0; i<NUM_LIGHTS; i++){
- strip.setPixelColor(i, high);
- strip.show();
- }
- }
- // =========================================================================================================
- if (counter == 2) {
- delayValue = map(analogRead(ColorPotPin), 0, 1024, 500, 1);
- uint32_t change = strip.Color(colorValueRed, colorValueGreen, colorValueBlue);
- strip.setBrightness(brightnessPot);
- for( int i = 0; i<NUM_LIGHTS; i++){
- strip.setPixelColor(i, change);
- strip.show();
- }
- if (fadeValue == 256) {
- fadeValue = 0;
- }
- else {
- fadeValue += 1;
- delay(delayValue);
- }
- delay(10);
- }
- // =========================================================================================================
- if (counter == 3) {
- uint32_t change = strip.Color(255, 255, 255);
- strip.setBrightness(brightnessPot);
- for( int i = 0; i<NUM_LIGHTS; i++){
- strip.setPixelColor(i, change);
- strip.show();
- }
- }
- // =========================================================================================================
- if (counter == 4) {
- rainbow(2);
- }
- // =========================================================================================================
- if (counter == 5) {
- int r = 255;
- int g = 96;
- int b = 12;
- for(int x = 0; x <50; x++)
- {
- int flicker = random(8,40);
- int r1 = r-flicker;
- int g1 = g-flicker;
- int b1 = b-flicker;
- if(g1<0) g1=0;
- if(r1<0) r1=0;
- if(b1<0) b1=0;
- strip.setPixelColor(x,r1,g1, b1);
- strip.setBrightness(brightnessPot);
- }
- strip.show();
- delay(random(40,125));
- }
- }
- // =========================================================================================================
- void rainbow(uint8_t wait) {
- uint16_t i, j;
- speedValue = map(analogRead(ColorPotPin), 0, 1024, 25, 1);
- for(j=0; j<256; j++) {
- for(i=0; i<strip.numPixels(); i++) {
- strip.setPixelColor(i, Wheel((i*3+j) & 255));
- int brightnessPot = map(analogRead(brightnessPotPin), 0, 1024, 1, 255);
- strip.setBrightness(brightnessPot);
- buttonState = digitalRead(2);
- if (buttonState == HIGH) {
- counter = 5;
- delay(50);
- Serial.println(counter);
- }
- }
- strip.show();
- delay(speedValue);
- }
- }
- uint32_t 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);
- }
- }
- // =========================================================================================================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement