Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
77 lines (59 sloc) 1.44 KB
#include <RBD_Timer.h>
#include <RBD_Light.h>
#include "SD.h"
#include "TMRpcm.h"
#include "SPI.h"
#define SD_ChipSelectPin 4
TMRpcm tmrpcm;
int redpin=3; //Pin 10
int greenpin=5; //Pin 11
int bluepin=6; //Pin 12
int colorr = 0;
int colorg = 0;
int colorb = 0;
long flickerTime = 0;
int played = 0;
RBD::Light eye(10);
int pirPin = 7;
char *sounds[6] = {"slimer.wav", "growl.wav", "growl2.wav", "scream.wav", "scream2.wav", "scream3.wav"};
void setup(){
// SOUND
tmrpcm.speakerPin = 9;
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("SD fail");
}
// MOTION SENSOR
pinMode(pirPin, INPUT);
// COLOR LED
randomSeed(analogRead(0));
tmrpcm.setVolume(6);
eye.fade(1000,6000,1000,2000);
}
void loop(){
// DETECT MOTION
if (digitalRead(pirPin)){
// PLAY SOUND IF SOUND ISN'T PLAYING AND HASN'T ALREADY PLAYED
if (!played && !tmrpcm.isPlaying()){
tmrpcm.play(sounds[random(6)%6]);
played = 1;
}
// TURN LIGHT RED
analogWrite(redpin, 255);
analogWrite(greenpin, 0);
analogWrite(bluepin, 0);
} else {
played = 0;
// CANDLE FLICKER
if (millis() >= flickerTime){
flickerTime = millis() + random(600);
colorr = random(128);
colorg = random(255-colorr);
colorb = random(20);
analogWrite(redpin, 128+colorr);
analogWrite(greenpin, colorg);
analogWrite(bluepin, colorb);
}
}
eye.update();
}