daily pastebin goal
91%
SHARE
TWEET

Untitled

a guest Aug 14th, 2018 70 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
  1. #include <AFMotor.h>
  2. #include <Adafruit_NeoPixel.h>
  3. #ifdef __AVR__
  4.   #include <avr/power.h>
  5. #endif
  6.  
  7. // Connect a stepper motor with 48 steps per revolution (7.5 degree)
  8. // to motor port #2 (M3 and M4)
  9. AF_Stepper motor(48, 1);
  10. Adafruit_NeoPixel left = Adafruit_NeoPixel(12, 9, NEO_GRB + NEO_KHZ800);
  11. Adafruit_NeoPixel right = Adafruit_NeoPixel(12, 10, NEO_GRB + NEO_KHZ800);
  12.  
  13. void setup() {
  14.   motor.setSpeed(100);  // 10 rpm  
  15.   left.begin();
  16.   right.begin();
  17. }
  18.  
  19. void loop() {
  20.   flashEyes();
  21.   motor.step(300, FORWARD, SINGLE);
  22.   flashEyes();
  23.   motor.step(300, BACKWARD, SINGLE);
  24.   flashEyes();
  25.   motor.step(300, FORWARD, DOUBLE);
  26.   flashEyes();
  27.   motor.step(300, BACKWARD, DOUBLE);
  28.   flashEyes();
  29.   motor.step(300, FORWARD, INTERLEAVE);
  30.   flashEyes();
  31.   motor.step(300, BACKWARD, INTERLEAVE);
  32.   flashEyes();
  33.   motor.step(300, FORWARD, MICROSTEP);
  34.   flashEyes();
  35.   motor.step(300, BACKWARD, MICROSTEP);
  36.   flashEyes();
  37. }
  38.  
  39. void flashEyes() {
  40.   setRed();
  41.   eyesOff();
  42.   setRed();
  43.   eyesOff();
  44.   setRed();
  45.   eyesOff();
  46.   setRed();
  47.   eyesOff();
  48.   setRed();
  49. }
  50.  
  51. void setRed() {
  52.  for(int lightLevel=0;lightLevel<255;lightLevel++){
  53.     for(int i=0;i<16;i++){
  54.     left.setPixelColor(i, left.Color(lightLevel,0,0));
  55.     right.setPixelColor(i, right.Color(lightLevel,0,0));
  56.     left.show();
  57.     right.show();
  58.   }
  59.   delay(10);
  60.  }
  61.   delay(200);
  62. }
  63.  
  64. void eyesOff() {
  65.   for(int lightLevel=255;lightLevel>0;lightLevel--){
  66.     for(int i=0;i<16;i++){
  67.     left.setPixelColor(i, left.Color(lightLevel,0,0));
  68.     right.setPixelColor(i, right.Color(lightLevel,0,0));
  69.     left.show();
  70.     right.show();
  71.   }
  72.   delay(10);
  73.  }
  74.   delay(200);
  75. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top