Back to Parent

#include "neopixel.h"
#include <math.h>

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D0
#define PIXEL_COUNT 16
#define PIXEL_TYPE WS2812

int pixel_position = 0;
int i = 0;
int j = 0;
int k = 0;
int servoPin = A5;
Servo myServo; //create servo object
int Pos = 0;

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

void setup(){

  Serial.begin( 9600 );
  myServo.attach(A5);
  strip.begin();
  strip.setBrightness(5);
  strip.show(); // Initialize all pixels to 'off'

}

void loop(){
  uint16_t i;
  for(i=0; i<strip.numPixels(); i++) {
    uint32_t white = strip.Color(255, 255, 255);
    strip.setPixelColor(i, white);
    strip.show();
    delay(500);

    if (i == strip.numPixels() -1 ){
      all_red();
    }

  }
}

void all_red(){
  uint32_t red = strip.Color(255, 0, 0);
  for(j=0; j<strip.numPixels(); j++){
  strip.setPixelColor(j, red);
  }
  strip.show();
  shake();
  strip.clear();
}

void shake(){
for(k = 0; k < 10; k++){
    for(Pos = 0; Pos < 45; Pos += 5) // servo goes from 0 degrees to 180 degrees
   {         // in steps of 1 degree
   myServo.write(Pos);    // tell servo to go to position in
            // variable 'pos'
   delay(15);      // waits 15ms for the servo to reach
            // the position
   }
   for(Pos = 45; Pos>=1; Pos-=5)  // goes from 180 degrees to 0 degrees
   {
   myServo.write(Pos);    // tell servo to go to position in
            // variable 'pos'
   delay(15);      // waits 15ms for the servo to reach
            // the position
   }
 }
}
Click to Expand

Content Rating

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

0