Skills Dev IV: Working with Outputs - Motors and Movement
Made by Shih-Hsueh Wang
Made by Shih-Hsueh Wang
Created: November 23rd, 2022
// 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
A weather indicator: Use a DC motor fan with the neopixel LEDs to be a cue when the weather is not good. Video