Meet the Pumpkinsteins (Noa & Aaron)
The Pumpkintstein sister is a life loving pumpkin that loves to eat and receive a lot of attention. She makes happy sounds when you rub her single pot ear and has peaceful, deep-blue LED eyes. With her super sensitive maxsonar nose, she can detected if you walk away, then her eyes will turn red to express how disappointed she is. The Pumpkintstein brother has the exact opposite nature. He hates when people get too close to him, and his eyes turn back green when you give hime some space, peace and quiet. Both of the pumpkins loooooove candies. If you feed them with candies, their eyes blink in happiness and they produce cheerful tunes. All this will happen thanks to lighten mouths equipped with photo resistors that respond to the candies blocking the direct light.
//Pumpkinstein code:\\ int lightPin = 3; //Photo resistor = A3 int threshold = 250; const int pwPin = 6; long pulse, inches, cm; //eyes: int redEye = 3; int blueEye = 4; //Green //mouth: #include "pitches.h" int melody[] = { NOTE_C5,NOTE_C7, NOTE_C6, NOTE_C7, NOTE_C5, NOTE_D4, NOTE_C6, NOTE_C7}; int noteDurations[] = { 4, 8, 8, 4,6,4,6,4 }; // speakers: int speakerPin1 = 9; int pitchPin1 = 0; int readingPitch1 = 0; int frequency1 = 0; int prevVal1 = 0; int currentVal1 = 0; long lastTimeMoved = 0; int shakeTime = 1000; void setup(){ Serial.begin(9600); pinMode(redEye, OUTPUT); pinMode(blueEye, OUTPUT); } void loop(){ if(analogRead(lightPin) < threshold ){ for (int thisNote = 0; thisNote < 8; thisNote++) { int noteDuration = 600/noteDurations[thisNote]; tone(speakerPin1, melody[thisNote],noteDuration); int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // noTone(speakerPin1); } blink2(); blink1(); delay(100); } pulse = pulseIn(pwPin, HIGH); //147uS per inch inches = pulse/147; //change inches to centimeters cm = inches * 2.54; Serial.print("sonar value = "); Serial.print(inches); Serial.print("in, "); Serial.print(cm); Serial.print("cm"); Serial.println(); if (inches > 45){ digitalWrite(redEye, HIGH); digitalWrite(blueEye,LOW); } else { digitalWrite(redEye, LOW); digitalWrite(blueEye,HIGH); } readingPitch1 = analogRead(pitchPin1); currentVal1 = analogRead(pitchPin1); if (prevVal1 != currentVal1) { frequency1 = map(readingPitch1, 0, 1023, 3000, 5000); // 100Hz -> 5kHz Serial.print("frequency1 = "); Serial.println(frequency1); tone(speakerPin1, frequency1, random(100)); } if(millis() - lastTimeMoved > shakeTime){ noTone(pitchPin1); } else { lastTimeMoved = millis(); prevVal1 = currentVal1; } delay(10); } //Functions:// void blink1(){ digitalWrite(blueEye, HIGH); digitalWrite(blueEye, LOW); delay(200); } void blink2(){ digitalWrite(blueEye, HIGH); digitalWrite(blueEye, LOW); delay(400); digitalWrite(blueEye, HIGH); digitalWrite(blueEye, LOW); delay(400); }</pre> <pre>
Reply