Back to Parent

// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

#define PIXEL_PIN D2
#define PIXEL_COUNT 8
#define PIXEL_TYPE WS2812

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int motorPin = D3;



bool shouldActive = false;

void setup() {
    
    strip.begin();
    strip.show();
    
    Serial.begin(9600);
    pinMode(motorPin, OUTPUT);
    
    Particle.function ("Fan Control", FanControl);
}

void loop() {
    
    if (shouldActive){
        Serial.println ("Fan On");

        for (int i = 0; i <= 255; i++){
            analogWrite (motorPin, i);
            
            for (int k = 0; k < strip.numPixels(); k ++){
                strip.setPixelColor (k, i, i/2, i);

            }
            strip.show();
            delay(10);
        }
        
        delay (5000);
        
        for (int i = 255; i >= 0; i--){
            analogWrite (motorPin, i);
            
            for (int k = 0; k < strip.numPixels(); k ++){
                strip.setPixelColor (k, i, i/2, i);
            }
            strip.show();
            delay(10);
         
        }

      shouldActive = false;      

    }
    
}

int FanControl (String cmd){
   
    if (cmd.equals ("on")){
        shouldActive = true;
    }else if (cmd.equals ("off")){
        shouldActive = false;
    }
    
    return 1;           

}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0