Josh Lopez-Binder, Assignment 09

joshua_1

A little wire monster with a movable jaw, eyes that blink in various ways, and a motor with an off-center weight that causes the monster to shake.

[flickr video=8148332532 secret=95662d48bb w=400 h=225]

#include <Servo.h>
Servo servo1;

int numLeds = 2;
int ledPins[2] = {
  13,12};
int sensorPin = A0;
int motorPin = 2;
int elapsed = 0;
int startMilli = 0;
int timeBlink = 100; //millis
boolean eyesAreOn =false;
boolean buttonWasPressed = false;

void setup(){
  Serial.begin(9600);
  for(int i = 0; i < numLeds; i++){
    pinMode(ledPins[i], OUTPUT);

  }
  pinMode(motorPin, OUTPUT);
  //pinMode(sensorPin, INPUT);
  servo1.attach(9);
}

void loop(){

  int sensorVal = analogRead(sensorPin);
  Serial.println(sensorVal);
  if(sensorVal <10){
    rawr();
  }
}

void rawr(){

  startMilli = millis();
  for(int angle = 0; angle= timeBlink){
      startMilli = millis();
      for(int i = 0; i< numLeds; i++){
        if(eyesAreOn){
          digitalWrite(ledPins[i], LOW);
        } 
        else {
          digitalWrite(ledPins[i], HIGH);
        }
      }
      eyesAreOn = !eyesAreOn;
    }
    servo1.write(angle);
    delay(20);

    for(int i = 0; i< numLeds; i++){
      digitalWrite(ledPins[i], LOW);

    }

  }
  digitalWrite(motorPin, HIGH);
  //freak out eyes, freak out motor
  for(int i = 0; i<45; i++){
    int ledRand1 = random(0,100);
    int ledRand2 = random(0,100);
    if(ledRand1<=50){
      digitalWrite(ledPins[0], HIGH);
    } else{
      digitalWrite(ledPins[0],LOW);
    }
    if(ledRand2 <=50){
      digitalWrite(ledPins[1],HIGH);
    } else{
      digitalWrite(ledPins[1],LOW);
    }
    delay(70);
  }
  digitalWrite(motorPin, LOW);

  servo1.write(10);

}

Post a comment