SPACE SQUID OF DOOOOOOM!!!!
So my Beep Boop creature is a squid. He loves the dark and hates the light. He’ll increasingly beep faster the longer he’s upset until he dies. He can be revived by being immersed in full darkness for a little while. He’ll get more excited the longer he’s in the dark.
::BONUS::When he’s upset his eyes will blink red as well.
#include "pitches.h" //list of the frequencies of most notes
int counter=0;
int photoPin=0;
int speaker=6;
//the reading must be bellow each of these values to ellicit that emotion
int excitedPoint=120;
int neutralPoint=180;
//higher than neutral results in dying
int reading; //holds the current photo reading
String state="neutral";
//using resistor: gold, red, green, brown
boolean dead=false;
int reviveCounter=0; //counts how logn the dead creature has been in darkness
// These are for the LED eyes
const int ledPin = 13;
int ledState = LOW; // ledState used to set the LED
long previousMillis = 0;
long interval = 1000;
void setup(){
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop(){
noTone(speaker);
//checks to see what state the creature is in
reading=analogRead(photoPin);
if (readingexcitedPoint && readingneutralPoint && state!="screaming"){
counter=0;
state="screaming";
}
//Deal with the various states
//is it dead?
if (dead){
Serial.println("DEAD");
if (random(100)==0)
PlayDeathGasp();
interval = random(100,1300);
RedEye(interval);
//if it is in darkness logn enough, it should revive
if (reading100){
Serial.println("CHECK IT");
//wait a few seconds between playing bliss sound
if (counter%200==0) {
PlayBliss();
}
}
else if (counter%20==0){
//if not, keep upping counter and play the exciting
PlayExcited();
}
}
if (state=="neutral"){
if (counter==1){
PlayNeutral(); //play the sound
}
//if it's been neutral for a while, make sure some time passes between making sounds
//then play it randomly
if (counter>200){
if (random(0,100)==0)
counter=0; //reset counter
}
}
if (state=="screaming"){
if (counter%20==0)
PlayScream();
interval = 500;
RedEye(interval);
if (counter>100){
PlayDying();
dead=true;
}
}
}
Serial.println(state);
counter++;
Serial.println(analogRead(photoPin));
//Serial.println(counter);
}
void PlayNeutral(){
//neutral tone sare played in a series of two.
int notes[]={
NOTE_D4, NOTE_B3, NOTE_A3, NOTE_F3, NOTE_DS3, NOTE_CS3 };
int start=random(0,2) *2;
for (int i=start; i<start+2; i++){
tone(speaker, notes[i]);
delay(500);
noTone(speaker);
delay(300);
}
}
//"I'm bursting with joy!"
void PlayBliss(){
//oscilate between two ranges that keep moving up
//originaly 512
int startVal=512;
int endVal=860;
int range=100;
int val=startVal;
int incr=random(1,3);
while(val<endVal){
//send it up
int tempMax=val+range; //how far up to go with this pass
for (val; valtempMin; val-=incr){
tone(speaker, val);
delay(3);
}
}
//hold the last value for a little while
delay(500);
}
void PlayScream(){
int scream[] = {
NOTE_B4, 0, NOTE_G4, 0, NOTE_E4, 0, NOTE_D4 };
int screamDurations[] = {
4,16,4,16,4,16,1 };
for (int thisNote = 0; thisNote endVal; i--){
tone(speaker, i);
delay(6);
}
//now create two beeps.
noTone(speaker);
delay(200);
tone(speaker, 300);
delay(500);
noTone(speaker);
delay(200);
tone(speaker, 200);
delay(500);
}
void PlayExcited(){
int levelAdjust=map(reading,0,excitedPoint, 300,0);
int toneA=NOTE_B4+levelAdjust;
int toneB=NOTE_G5+levelAdjust;
int counterAdjust=map(counter,0,100,0,40);
for (int i=0; iendVal; i-=30){
tone(speaker,i);
delay(30000/i);
}
noTone(speaker);
delay(500);
//a few little burbles
for (int i=0; i<3; i++){
PlayDeathGasp();
}
}
//Burbles and gurgles
void PlayDeathGasp(){
tone(speaker, random(50,70));
delay(random(500,1000));
noTone(speaker);
delay(random(500,1000));
}
//"I'm coming back to life!"
void PlayRevive(){
int startVal=50;
int endVal=NOTE_D5;
for (int i=startVal; i<endVal; i+=30){
tone(speaker,i);
delay(30000/i);
}
noTone(speaker);
delay(500);
for (int i=0; i interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (ledState == LOW)
ledState = HIGH;
else
ledState = LOW;
// set the LED with the ledState of the variable:
digitalWrite(ledPin, ledState);
}
}




Explanation of squid of doom! « Making Toys 11:19 pm on February 7, 2011 Permalink |
[…] Explanation of squid of doom! […]