~~~~~~~~~~~~~~~~~~~~~~~~
DESCRIPTION
~~~~~~~~~~~~~~~~~~~~~~~~
Inspired by clemens.meyer’s Light Chaser game (http://courses.ischool.berkeley.edu/i262/f13/content/clemensmeyer/lab-4-fsrs-and-photocells-light-chaser-game) from assignment 4, I wanted to create a similar screen-to-photocell receptor interaction game. I created an airplane with one photocell on each wing, which when used with a background that has a gradient on it, will calculate the difference between photocell values to tell if you are banking the plane to the left or to the right. I set the piezzo to produce different notes depending on whether the plane is turning left, right, or maintaining a neutral wing position.
My end goal was to have it interact with a visual I made in processing that would update the screen to match with the turning of the plane (moving tree line and a compass in the corner). It was working well before I set it up to talk to Arduino and then I started getting errors about invalid access of memory location which I haven’t yet been able to troubleshoot all the way.
~~~~~~~~~~~~~~~~~~~~~~~~
COMPONENTS
~~~~~~~~~~~~~~~~~~~~~~~~
1- Arduino Uno
1 - Breadboard
2 - Photocell Receptor
2 − 10k Ω Resistors
1 - Piezzo buzzer
assorted wires
cardboard
~~~~~~~~~~~~~~~~~~~~~~~~
ARDUINO CODE
~~~~~~~~~~~~~~~~~~~~~~~~
/** PLANE_OUT
* (Jordan Arnesen, October 2013)
*
* Sends out controller values to the computer
* for use in Plane_Flier program.
*
*/
// analog inputs
int inPhotL = 0; // PHOT input connected to pin 0 - left wing
int inPhorR = 1; // PHOT input connected to pin 1 - right wing
// output
int buzz = 7; // piezzo output on pin 7
// values
int photL = 0; // variable to store value from left wing Phot
int photR = 0; // variable to store value from right wing Phot
int diff = 0; // difference between L and R wing values
int count = 0; // space out the outputs to processing
void setup()
{
Serial.begin(9600); // open communication for Processing to read
pinMode(buzz, OUTPUT);
}
void loop()
{
photL = analogRead(inPhotL);
photR = analogRead(inPhorR);
diff = photL - photR;
if (diff > 100) {
digitalWrite(buzz, HIGH);
delayMicroseconds(1915); // note 'c'
digitalWrite(buzz, LOW);
delayMicroseconds(1915);
}
else if (diff < -100) {
digitalWrite(buzz, HIGH);
delayMicroseconds(956); // note 'b'
digitalWrite(buzz, LOW);
delayMicroseconds(956);
}
//else {
digitalWrite(buzz, HIGH);
delayMicroseconds(1275); // note 'g'
digitalWrite(buzz, LOW);
delayMicroseconds(1275);
//}
if (count > 200) {
Serial.println(diff);
count =0;
}
count += 1;
}
- Login to post comments