/* *🔊Sound To Speech🗣 v1.1 *This program is for running your Teddy Ruxpin with a smartphone or other sound source *It works by using the readings from the headphone jack to know when to open mouth It also waits between 10-20 seconds and blinks the eyes *⭐Download latest version here https://www.instructables.com/EPWLFQQJHATIN23/step/6 *I AM STILL IMPROVING THIS MAKE SURE YOU HAVE LATEST VERSION *Created 05/21/18 *Last Updated 5/27/18 *Written by Jayden N. *Licenced under CC BY-SA 4.0 *https://creativecommons.org/licenses/by-sa/4.0/ */ //Varibles //Motors int EyeOpen = 12; int EyeClose = 13; int MouthOpen = 9; int MouthClose = 8; //Sound int SoundValue = 0; boolean QuietSound = false; boolean MediumSound = false; boolean LargeSound = false; //others int blinktimer; void setup(){ //Intiate motors pinMode(EyeOpen,OUTPUT); pinMode(EyeClose,OUTPUT); pinMode(MouthOpen,OUTPUT); pinMode(MouthClose,OUTPUT); //serial communication for testing signal Serial.begin(9600); //Bear Startup viewable in serial monitor Serial.println("🔊Sound To Speech🗣 v1.01"); delay(600); Serial.println("BY JAYDEN17"); delay(100); Serial.println("Correcting Eyes..."); blinkeyes(); Serial.println("Correcting Mouth..."); largetalk(); delay(100); Serial.println("Setup Complete..."); delay(100); Serial.println("Volume communication started"); } void loop(){ readsound(); if (SoundValue>0){ Serial.println(SoundValue); } if (QuietSound == true){ smalltalk(); }else{ if(MediumSound == true){ mediumtalk(); }else{ if(LargeSound == true){ largetalk(); } } } } void largetalk(){ Serial.println("LARGE"); digitalWrite(MouthClose,LOW);//stops closing mouth digitalWrite(MouthOpen,HIGH);//start opening mouth delay(700);//wait .7 seconds digitalWrite(MouthClose,HIGH);//starts closing mouth digitalWrite(MouthOpen,LOW);//stops opening mouth delay(700);//wait .7 seconds digitalWrite(MouthClose,LOW);//stops closing mouth } void mediumtalk(){ Serial.println("MEDIUM"); digitalWrite(MouthClose,LOW);//stops closing mouth digitalWrite(MouthOpen,HIGH);//start opening mouth delay(500);//wait .5 seconds digitalWrite(MouthClose,HIGH);//starts closing mouth digitalWrite(MouthOpen,LOW);//stops opening mouth delay(500);//wait .5 seconds digitalWrite(MouthClose,LOW);//stops closing mouth } void smalltalk(){ Serial.println("SMALL"); digitalWrite(MouthClose,LOW);//stops closing mouth digitalWrite(MouthOpen,HIGH);//start opening mouth delay(300);//wait .3 seconds digitalWrite(MouthClose,HIGH);//starts closing mouth digitalWrite(MouthOpen,LOW);//stops opening mouth delay(300);//wait .3 seconds digitalWrite(MouthClose,LOW);//stops closing mouth } void blinkeyes(){ digitalWrite(EyeOpen,LOW);//stop opening eye digitalWrite(EyeClose,HIGH);//start closing eye delay(800);//wait .8 seconds digitalWrite(EyeClose,LOW); //stop closing eye digitalWrite(EyeOpen,HIGH); //start opening eye delay(800);//wait .8 seconds digitalWrite(EyeOpen,LOW); blinktimer = random(2500,5000); Serial.println("Eyes Blinked"); } void readsound(){ SoundValue = analogRead(A0);//Reads sound value and stores it in SoundValue varible if (SoundValue >= 1 && SoundValue <= 4){ QuietSound = true;//sets QuietSound to true MediumSound = false;//sets MediumSound to false LargeSound = false;//sets LargeSound to false }else{ if (SoundValue >= 5 && SoundValue <= 10){ MediumSound = true;//sets MediumSound to true QuietSound = false;//sets QuietSound to false LargeSound = false;//sets LargeSound to false }else{ if (SoundValue >= 11){ LargeSound = true;//sets LargeSound to true QuietSound = false;//sets QuietSound to false MediumSound = false;//sets MediumSound to false }else{ LargeSound = false;//sets LargeSound to false QuietSound = false;//sets QuietSound to false MediumSound = false;//sets MediumSound to false } } } delay(1); }