|
Main Links:
Final Projects
|
Main /
PetCombatRoyaleBlanka Lenart Concept ![]() Inspiration Pet Combat Royale is based in animal play and does not promote violence toward animals in any way. No animals were hurt in the making of this project. PCR plays with the idea of a perceived activity. The animals appear to be fighting, but they are play-wrestling. Components
Code
//////////////////////////////////////////////
/* PET COMBAT ROYALE
MAGNET
Final Project
Phys Comp Fall 2006
12/13/06
Tim McNerney, code warrior
Blanka Lenart, design maven
*/
//////////////////////////////////////////////
// declare variables:
int hesPin = 2; // digital input pin for the hall effect sensor
int LedPin3 = 3; // digital output pin for an LED
int LedPin4 = 4; // digital output pin for an LED
int LedPin5 = 5; // digital output pin for an LED
int LedPin6 = 6; // digital output pin for an LED
int hesState = 1; // the state of the hall effect sensor
void setup() {
pinMode(hesPin, INPUT); // set the hes pin to be an input
pinMode(LedPin3, OUTPUT); // set the LED pin to be an output
pinMode(LedPin4, OUTPUT); // set the LED pin to be an output
pinMode(LedPin5, OUTPUT); // set the LED pin to be an output
pinMode(LedPin6, OUTPUT); // set the LED pin to be an output}
}
void loop() {
// read the hes input:
hesState = digitalRead(hesPin);
if (hesState == 0) {
// if the switch is closed:
digitalWrite(LedPin3, HIGH); // turn on the LED
digitalWrite(LedPin4, HIGH); // turn on the LED
digitalWrite(LedPin5, HIGH); // turn on the LED
digitalWrite(LedPin6, HIGH); // turn on the LED
}
else {
// if the switch is open:
digitalWrite(LedPin3, LOW); // turn off the LED
digitalWrite(LedPin4, LOW); // turn off the LED
digitalWrite(LedPin5, LOW); // turn off the LED
digitalWrite(LedPin6, LOW); // turn off the LED
}
}
Infrared Sensor
//////////////////////////////////////////////
/* PET COMBAT ROYALE
INFRARED
Final Project
Phys Comp Fall 2006
12/13/06
Tim McNerney, code warrior
Blanka Lenart, design maven
Special thanks to:
Team Lightbox: Greg Stringer, Minsoo Lee, Rory Nugent
-- the IR code was taken from their midterm.
Nike the dog and Taxi the cat
-- no animals were harmed in this production.
*/
//////////////////////////////////////////////
// Infrared sensor in analog pin 0
// triggers YELLOW LEDs in digital pins 2, 3, 4, and 5
int irSensor = 0; // analog IR sensor #0 pin
int irValue = 0; // analog
// YELLOW LED lights for infrared sensor
int lightLED2 = 2;
int lightLED3 = 3;
int lightLED4 = 4;
int lightLED5 = 5;
//////////////// M A G I C ////////////////////
int irNoiseSensor = -1; // noise readings from each sensor
unsigned long time = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
time = millis(); // read current run time in milliseconds
if(time < 3000) // initialize lightbox if time is less than 3 seconds (3000ms)
Initialize();
else if(time >= 3000)
{
//read analog values from the IR detectors (nearby IR light)
irValue = analogRead(irSensor);
calibrate_readings(); //calibrate the analog IR readings (i.e. remove noise and limit values from 0-255)
//write analog readings to the LEDs
analogWrite(lightLED2,255-irValue);
analogWrite(lightLED3,255-irValue);
analogWrite(lightLED4,255-irValue);
analogWrite(lightLED5,255-irValue);
Serial.print(irValue);
Serial.print("\t");
Serial.println();
delay(10);
}
}
// initialize the light box by running start-up sequence and scanning for ambient infrared noise
void Initialize()
{
int tempRead = 0;
//turns on LEDs according to the time
if(time >= 0 && time < 1000) {
analogWrite(lightLED2,0);
analogWrite(lightLED3,0);
analogWrite(lightLED4,0);
analogWrite(lightLED5,0); }
else if(time >= 1000 && time < 2000) {
tempRead = analogRead(irSensor); //grab an analog reading from each sensor
//check to see if the new analog reading is higher than the stored noise reading, if so make the new reading the new noise value
if(tempRead > irNoiseSensor)
irNoiseSensor = tempRead;
}
}
void calibrate_readings()
{
//remove ambient noise from readings
irValue = irValue - irNoiseSensor;
//be sure no values go below 0
if(irValue < 0)
irValue = 0;
//truncate all values at 255
if(irValue > 255)
irValue = 255;
}
Assembly
Here is the constructed pen, before decorations We took a break from building to make this xmas tree! The finished product Play testers in action (video) Going Forward Improvements Have a happy holiday everyone! ![]() |