Stephanie Cheung – Hallowino

Description
My project was the coffin box that was activated when the lid was opened! A photoresistor inside detected the increased light levels and turned on three pulsing LEDs, a randomly jittering servo motor, and a continuously spinning gear motor.
I had two little skeleton toys and chains attached to the servo that would jiggle around when it moved, and there were two plastic spiders on the gear motor that circled each other on a web. The LEDs were diffused by the gauze spiderweb and two little ghost cutouts were entangled in it.

Picture

Fritzing

Video


Code

int led[] = {
  3,5,6}; 
int brightnessArray[] = {
  0,0,0};  
int fadeAmountArray[] = {
  5,3,8};

int prevSecond = 0; 

#include 
Servo servo;

const int sensorPin = 0;
int lightLevel, high = 0, low = 1023;

const int motorPin = 11;

void setup()  { 
  pinMode(motorPin, OUTPUT);

  servo.attach(9);
  Serial.begin(9600);

  int i;
  for (i=0; i<=2; i++){
    pinMode(led[i], OUTPUT);
  }
} 

void loop()  { 
  lightLevel = analogRead(sensorPin);
  lightLevel = map(lightLevel, 400, 900, 0, 255);
  lightLevel = constrain(lightLevel, 0, 255);
  Serial.println( lightLevel); 

  if (lightLevel<=125){
    for (int i=0; i<=2; i++){
      int magic[] = {
        (int) (128 + 127 * sin (millis()/400.0)), (int) (128 + 127 * sin (millis()/700.0)), (int) (128 + 127 * sin (millis()/1000.0))                  };
      analogWrite(led[i], magic[i]); 
      delay(1); 
    }

    int currSecond = millis()/600;
    if (currSecond != prevSecond){
      Serial.println( "Do something trigger!"); 
      int position; 
      position = random(180);
      servo.write(position);
    }
    prevSecond = currSecond; // last thing to do 

    analogWrite(motorPin, 100);
  }

  else{
    for(int i=0; i<=2; i++){
      analogWrite(led[i], LOW);
    }
  }
}

Post a comment