/* A = motion sensing = 0000, 0001, 0009, 0011; 0013 B = water flow C = hardcode */ /* Sounds and Corresponding File Names: SUE 0000 = Whoa, I'm feeling a bit of rain through my pipes today! 0001 = (A) You know, the microwave was just talking about you 0002 = (A) The silverware was just telling me there's a drought?! That can't be good. 0003 = (C) Hey, be kind to my handles! Slow and steady now. 0004 = (B) Oh that looks like it could use some soap. 0005 = (B) The water keeps talking about the Hetchy reservoir. Seems like its spent a lot of time there. 0006 = (B) Cut back on the water! I'm in charge of it! Understand? 0007 = (B) Did you know this water came all the way from the Sierra Nevada? Give it some respect please! 0008 = (B) I'm giving you an important task. Keeping me clean. I want to shine like an ice cube. 0009 = (A) I feel like you could use a nice glass of water right now. 0010 = (B) Ah. Now isnt thaat nice? 0011 = (A) A sponge a day keeps the mildew away. STUART 0012 = (C) Hey! The waters scalding! 0013 = (A) Hope youre having a good day! 0014 = (B) Heres some Sierra Nevada...*water plays* 0015 = (B) You know what this reminds me of? *song plays* */ #include //#include //#include int resetPin = 2; // The pin number of the reset pin. int clockPin = 3; // The pin number of the clock pin. int dataPin = 4; // The pin number of the data pin. int busyPin = 5; // The pin number of the busy pin. int flexPin = A0; int motionPin = 7; int stuartMotionPhrases[] = {13}; int stuartWaterPhrases[] = {14,15}; int stuartSpecialPhrases[] = {12}; int sueMotionPhrases[] = {0,1,2,9,11}; int sueWaterPhrases[] = {4,5,6,7,8,10}; int sueSpecialPhrases[] = {3}; int demoPin = 12; int count = 0; int flexValueCenter = 770; int pirVal; int flexValue; int prevFlexValue; int motionDetected = 0; int waterDetected = 0; int waterFlowTotalTime = 0; int motionTotalTime = 0; int flexEnabled = 1; int motionEnabled = 1; int SUE = 0; int STUART = 1; int voice = 1; int water = 0; int motion = 1; int special = 2; /* Create an instance of the Wtv020sd16p class. 1st parameter: Reset pin number. 2nd parameter: Clock pin number. 3rd parameter: Data pin number. 4th parameter: Busy pin number. */ Wtv020sd16p wtv020sd16p(resetPin,clockPin,dataPin,busyPin); void setup() { //Initializes the module. Serial.begin(9600); wtv020sd16p.reset(); pinMode(flexPin, INPUT); pinMode(motionPin, INPUT); pinMode(demoPin, INPUT); flexValue = analogRead(flexPin); prevFlexValue = flexValue; delay(5000); } void loop() { if(motionEnabled) { pirVal = digitalRead(motionPin); } else { pirVal = HIGH; } prevFlexValue = flexValue; delay(300); if(flexEnabled) { flexValue = analogRead(flexPin); } else { flexValue = prevFlexValue; } //Serial.println("FLEXV") if(pirVal == LOW){ //was motion detected Serial.println("Motion"); if (digitalRead(demoPin)) { speakDemo(); } else { speak(motion); } } else if (flexValue - prevFlexValue > 5 ) { Serial.println("Flex"); Serial.println(prevFlexValue); Serial.println(flexValue); prevFlexValue = flexValue; if(digitalRead(demoPin)) { speakDemo(); } else { speak(water); } } } void speak(int phraseGroup) { if(voice == SUE) { if(phraseGroup == water) { int value = (int)random(6); wtv020sd16p.asyncPlayVoice(sueWaterPhrases[value]); } else if (phraseGroup == motion) { int value = (int) random(5); wtv020sd16p.asyncPlayVoice(sueMotionPhrases[value]); } else if (phraseGroup == special) { int value = (int) random(1); wtv020sd16p.asyncPlayVoice(sueSpecialPhrases[value]); } } else if(voice==STUART) { if(phraseGroup == water) { int value = (int)random(2); wtv020sd16p.asyncPlayVoice(sueWaterPhrases[value]); } else if (phraseGroup == motion) { int value = (int) random(1); wtv020sd16p.asyncPlayVoice(sueMotionPhrases[value]); } else if (phraseGroup == special) { int value = (int) random(1); wtv020sd16p.asyncPlayVoice(sueSpecialPhrases[value]); } } delay(500); while(digitalRead(busyPin)) { //busy wait } } void speakDemo() { Serial.println("Demo"); Serial.println(voice); if(voice == SUE) { if(count > 11) { count = 0; } } else if (voice == STUART) { if (count > 15 || count < 12) { count = 12; } } Serial.println(count); wtv020sd16p.asyncPlayVoice(count); delay(500); while(digitalRead(busyPin)) { //busy wait } count++; delay(2000); }