Change the Behavior of the StarLord Mask

Note: the servo motor on the mask may draw a significant amount of current. In theory this is no more than your laptop is capable of providing, but I will not be held responsible if you somehow managed to fry the USB port on your computer. So... I suggest plugging the mask into a powered USB hub (provided), then plug that into your computer. That should insulate your computer from anything risky.

There is also a battery pack with the mask. Please ask me how to set things up before starting.

The mask includes 3 components:

This is the current version of the script loaded on the Mask.

#include <Adafruit_NeoPixel.h>
#include <Servo.h>
#include <math.h>

Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, 4, NEO_GRB + NEO_KHZ800);

Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
int ldr=0,on=0;
int count=0;
int target,cur;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  pinMode(13,OUTPUT);  
  pinMode(8,INPUT_PULLUP);   // output is just to avoid another solder connection

  myservo.write(0);
  cur=0;

  strip.begin();
  strip.show(); // Initialize all pixels to 'off'

}

// the loop routine runs over and over again forever:
void loop() {
  int dr=digitalRead(8);
  if (dr==0 && ldr==1) {    // dr is the value of the switch. ldr is the previous value of the switch
     on^=1;
     if (on) { 
       target=120;          // We want the motor to run more slowly than its normal speed
     }
     else {
       target=0;
       strip.setPixelColor(0,0,0,0);
       strip.setPixelColor(1,0,0,0);
       strip.show();
     }
  }
  ldr=dr;

  if (on && cur==target) {
    int color=(int)(sin(count/12.0)*48.0+96.0);
    strip.setPixelColor(0,color,0,0);
    strip.setPixelColor(1,color,0,0);
    strip.show();
  }

  if (cur<target) {
    cur+=3;
    if (cur>target) cur=target;
    myservo.write(cur);
  }
  else if (cur>target) {
    cur-=3;
    if (cur<target) cur=target;
    myservo.write(cur);
  }

  count++;
  delay(20);  
}

That's it. There is nothing to turn in. When you're satisfied with your result, you're done.

LectureVideo/ArduinoLab/Mask (last edited 2015-02-23 14:15:30 by SteveLudtke)