## 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>
&nbsp;
<pre>

__ATA.cmd.push(function() {
__ATA.initDynamicSlot({
id: 'atatags-26942-64185e62b5a73',
location: 120,
formFactor: '001',
label: {
text: 'Advertisements',
},
creative: {
reportAd: {
text: 'Report this ad',
},
privacySettings: {
text: 'Privacy',

}
}
});
});
Rate this:	```

## Jason Kim Midterm: Stupid Pumpkin

1) Project Name: Stupid Pumpkin

The concept of the Stupid Pumpkin is relatively straightforward. It’s a pumpkin that looks stupid and a pumpkin that people would want to hit. Using two tilt sensors, I could detect if the pumpkin was hit from the left or from the right. If hit from the right side, the servo motor turns in a clockwise direction (counter clockwise if hit from left) and the Stupid Pumpkin makes a sad face and starts to cry. The LEDs representing the mouth of the pumpkin are controlled by a shift register. The eyes of the pumpkin are RGB LEDs that change color every time the pumpkin is hit. Near the nose (fading superbright blue LED) of the pumpkin is also a photocell that detects if the pumpkin’s nose is covered or if the lights are turned off. If the nose is covered or lights are turned off, the Stupid Pumpkin starts to cry as it is lonely and frightened. The inside of the pumpkin are all wires and circuit boards and uses no bread boards. Circuit boards are screwed on the inside wall of the pumpkin. The Arduino is powered by a 9V battery pack.

2) A photo of the electronics and final project

3) A short video demonstrating it

4) The Arduino code

```<pre>//Midterm Pumpkin Jason Kim

//Photocell
int photocellPin = A3;
int photocellReading;

//Servo Motor
#include <Servo.h>
Servo myServo;
int noTurn = 90;

//Shift Register 75HC595
int SER_Pin = 11;   //pin 14 on the 75HC595 bluewire
int RCLK_Pin = 8;  //pin 12 on the 75HC595 greenwire
int SRCLK_Pin = 12; //pin 11 on the 75HC595 yellowwire
#define number_of_74hc595s 1
#define numOfRegisterPins number_of_74hc595s * 8

//Pumpkin eyes
const int redPin = A0;
const int greenPin = A1;
const int bluePin = A2;
const boolean invert = true;

int color = 0;
int R, G ,B;

//Pumpkin tear eyes
int eyePin[] = {
6,3};

int eyePin2[] = {
9,10};

int brightness2 = 0;
int brightness3 = 0;

//Pumpkin nose
int brightness = 0;
int fadeAmount = 5;
int nosePin = 5;

//Pumpkin hit (tilt sensor)
int tiltPin[] = {
7,4};
int tiltState = 0;
int tiltState2 = 0;

//test led
int testPin = 13;

boolean registers[numOfRegisterPins];

void setup(){
Serial.begin(9600);
myServo.attach(2);
myServo.write(noTurn);
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
pinMode(nosePin, OUTPUT);
for(int i = 0; i<2; i++){
pinMode(tiltPin[i], INPUT);
}
for(int j = 0; j<2; j++){
pinMode(eyePin[j],OUTPUT);
}
for(int k = 0; k<2; k++){
pinMode(eyePin2[k],OUTPUT);
}
clearRegisters();
writeRegisters();
}

//set all register pins to LOW
void clearRegisters(){
for(int i = numOfRegisterPins - 1; i >=  0; i--){
registers[i] = LOW;
}
}
void writeRegisters(){
digitalWrite(RCLK_Pin, LOW);
for(int i = numOfRegisterPins - 1; i >=  0; i--){
digitalWrite(SRCLK_Pin, LOW);
int val = registers[i];
digitalWrite(SER_Pin, val);
digitalWrite(SRCLK_Pin, HIGH);
}
digitalWrite(RCLK_Pin, HIGH);
}

void setRegisterPin(int index, int value){
registers[index] = value;
}

void loop(){
tiltState = digitalRead(tiltPin[0]);
tiltState2 = digitalRead(tiltPin[1]);
photocellReading = analogRead(photocellPin);
photocellReading = 1023 - photocellReading;
if (photocellReading > 500 && photocellReading < 600){
myTear();
}
Serial.print("Photocell reading = ");
Serial.println(photocellReading);
//Pumpkin Eyes
myEye();
//Pumpkin Nose
myNose();
//Pumpkin Hit
myHit();
//Pumpkin Mouth
myHappy();
writeRegisters();
if(tiltState == HIGH){
myServo.write(111);
mySad();
myEyeHit();
writeRegisters();
myTear();
delay(500);
myServo.write(noTurn);
}
if(tiltState2 == HIGH){
myServo.write(71);
mySad();
myEyeHit();
writeRegisters();
myTear();
delay(500);
myServo.write(noTurn);
}
}
void myHappy(){
setRegisterPin(0, HIGH);
setRegisterPin(3, HIGH);
setRegisterPin(5, HIGH);
setRegisterPin(6, HIGH);
setRegisterPin(1, LOW);
setRegisterPin(2, LOW);
setRegisterPin(4, LOW);
setRegisterPin(7, LOW);
}
void mySad(){
setRegisterPin(1, HIGH);
setRegisterPin(2, HIGH);
setRegisterPin(4, HIGH);
setRegisterPin(7, HIGH);
setRegisterPin(0, LOW);
setRegisterPin(3, LOW);
setRegisterPin(5, LOW);
setRegisterPin(6, LOW);
}
void myNose(){
analogWrite(nosePin, brightness);
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255){
fadeAmount = -fadeAmount;
}
delay(30);
}
void myHit(){
if(tiltState == HIGH){
digitalWrite(testPin, HIGH);
}
else if(tiltState2 == HIGH){
digitalWrite(testPin, HIGH);
}
else{
digitalWrite(testPin, LOW);
}
}
void myTear(){
for(int i =0; i < 2; i++){
//one LED fade
for(int brightness2 = 0; brightness2 <= 255; brightness2 +=5){
analogWrite(eyePin[i], brightness2);
//      analogWrite(eyePin2[i],brightness2);
delay(10);
}
for(int brightness2 = 255; brightness2 >= 0; brightness2 -=5){
analogWrite(eyePin[i],brightness2);
//      analogWrite(eyePin2[i],brightness2);
delay(10);
}
}
}
void myLeftTear(){
for(int i = 0; i < 2; i++){
//one LED fade
for(int brightness3 = 0; brightness3 <= 255; brightness3 +=5){
//      analogWrite(eyePin[i],brightness2);
analogWrite(eyePin2[i],brightness3);
delay(10);
}
for(int brightness3 = 255; brightness3 >= 0; brightness3 -=5){
//      analogWrite(eyePin[i],brightness2);
analogWrite(eyePin2[i],brightness3);
delay(10);
}
}
}
void myEye(){
int brightnessEye = 255;
hueToRGB(color, brightnessEye);
analogWrite(redPin, R);
analogWrite(greenPin, G);
analogWrite(bluePin, B);
if(color > 255){
color = 0;
}
delay(10);
}
void myEyeHit(){
int brightness = 100;
hueToRGB(color, brightness);
analogWrite(redPin, R);
analogWrite(greenPin, G);
analogWrite(bluePin, B);
color+=60;
if(color > 255){
color = 0;
}
delay(10);
}
void hueToRGB( int hue, int brightness){
unsigned int scaledHue = (hue * 6);
unsigned int segment = scaledHue / 256; //segment 0 to 5 round the color wheel
unsigned int segmentOffset = scaledHue - (segment * 256); //position within segment
unsigned int complement = 0;
unsigned int prev = (brightness * ( 255 - segmentOffset)) / 256;
unsigned int next = (brightness * segmentOffset) / 256;
if(invert){
brightness = 255-brightness;
complement = 255;
prev = 255-prev;
next = 255-next;
}
switch(segment ){
case 0: //red
R = brightness;
G = next;
B = complement;
break;
case 1: //yellow
R = prev;
G = brightness;
B = complement;
break;
case 2: //green
R = complement;
G = brightness;
B = next;
break;
case 3: //cyan
R = complement;
G = prev;
B = brightness;
break;
case 4: //blue
R = next;
G = complement;
B = brightness;
break;
case 5: //magenta
default:
R = brightness;
G = complement;
B = prev;
break;
}
}
```

## Toccata CalaBach

The concept behind this pumpkin was inspired by the Toccata in Fugue D Minor by Bach. The teeth of the pumpkin are white keys/ switches, that when pressed to the bottom surface close the circuit and play a note through a piezo buzzer. If the first and the last key are both pressed at the same time, a short introduction of the Toccata in Fugue plays. The light of the pumpkin turns on at night, once a photoresistor reads values that are low enough to mean darkness. A little stuffed dead guy accompanies Toccata CalaBach, representing Johann Sebastian.

// CODE:

int photo= 0;
int led = 2;
int key1 = 3;
int key2 = 4;
int key3 = 5;
int key4 = 6;
int key5 = 7;
int key6 = 8;
int speakerOut = 9;

int debounce = 10;

int state= LOW;
int lastkeyvalue = LOW; // we start, assuming no motion detected
int val= 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
// variable for reading the key status
//******************************************************************************
// TONES ==========================================
// Start by defining the relationship between
// note, period, & frequency.
int c= 3830; // 261 Hz
int d= 3400; // 294 Hz
int e= 3038; // 329 Hz
int f= 2864; // 349 Hz
int g= 2550; // 392 Hz
int a= 2272; // 440 Hz
int b= 2028; // 493 Hz
int C= 1912; // 523 Hz
// Define a special note, ‘R’, to represent a rest
int O= 0;

// MELODY and TIMING =======================================
// melody[] is an array of notes, accompanied by beats[],
// which sets each note’s relative length (higher #, longer note)
int melody[] = {
a, g, a, O, g, f, e, d, 3615, d };
int beats[] = {
8, 8, 64, 64, 16, 16, 16, 16, 64, 64 };
int MAX_COUNT = sizeof(melody) / 2; // Melody length, for looping.

// Set overall tempo
long tempo = 10000;
// Set length of pause between notes
int pause = 1000;
// Loop variable to increase Rest length
int rest_count = 100; //<-BLETCHEROUS HACK; See NOTES

// Initialize core variables
int tone_ = 0;
int beat = 0;
long duration = 0;
//******************************************************************************

void setup() {
pinMode(speakerOut, OUTPUT);
pinMode(photo, INPUT); //photoresistor Analog
pinMode(key1, INPUT);
pinMode(key2, INPUT);
pinMode(key3, INPUT);
pinMode(key4, INPUT);
pinMode(key5, INPUT);
pinMode(key6, INPUT);
pinMode(led, OUTPUT);

Serial.begin(9600);
}

void loop(){
val1 = digitalRead(key1);
val2 = digitalRead(key2);
val3 = digitalRead(key3);
val4 = digitalRead(key4);
val5 = digitalRead(key5);
val6 = digitalRead(key6);
if (val1 == HIGH && val6 == HIGH){
playSong();
}else{
keyTones();
}
nightLight();

}

void keyTones(){
Serial.println(“val1”);
if (val1 == HIGH){
tone_=c;
duration= 640000;
playTone();
Serial.println(“YES = 1”);
}
if (val2 == HIGH){
tone_=d;
duration= 640000;
playTone();
Serial.println(“YES = 2”);
}
if (val3 == HIGH){
tone_=e;
duration= 640000;
playTone();
Serial.println(“YES = 3”);
}

if (val4 == HIGH){
tone_=f;
duration= 640000;
playTone();
Serial.println(“YES = 4”);
}
if (val5 == HIGH){
tone_=g;
duration= 640000;
playTone();
Serial.println(“YES = 5”);
}
if (val6 == HIGH){
tone_=a;
duration= 640000;
playTone();
Serial.println(“YES = 6”);
}
else {
digitalWrite(speakerOut, LOW);
}
if (val1 != lastkeyvalue ){
delay(debounce);
val1 = key1;
}
lastkeyvalue= val1, val2, val3, val4, val5, val6;

}

void nightLight(){
val= analogRead(photo);
// Serial.print(val);
Serial.print(10, BYTE);
delay(10);

if (val<400){
digitalWrite(led, HIGH);
}else{
digitalWrite(led, LOW);
}

}

void playSong() {
// Set up a counter to pull from melody[] and beats[]
for (int i=0; i 0) { // if this isn’t a Rest beat, while the tone has
// played less long than ‘duration’, pulse speaker HIGH and LOW
while (elapsed_time < duration) {

digitalWrite(speakerOut,HIGH);
delayMicroseconds(tone_ / 2);

// DOWN
digitalWrite(speakerOut, LOW);
delayMicroseconds(tone_ / 2);

// Keep track of how long we pulsed
elapsed_time += (tone_);
}
}
else { // Rest beat; loop times delay
for (int j = 0; j < rest_count; j++) { // See NOTE on rest_count
delayMicroseconds(duration);
}
}
}

c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel