/* * Cam the RamBorg * CURC project * Alison Nicole Craig * Spring 2009 */ int ledPin = 13; // Board LED connected to digital pin int button = 7; // button pad location int signalLow = 9; // - on button int redPin = 10; // RGB pins int greenPin = 12; int bluePin = 11; int spkrPin = 6; // Speaker is connected to digital pin 6 boolean mode = true; // true = light mode // false = sound/move mode int sensor = 0; // Pin for light sensor int value; // variable to store light value int xPin = 2; // Accelerometer pins: int yPin = 3; int zPin = 4; int xValue; // variables to store x int yValue; // y int zValue; // z void setup() { pinMode(ledPin,OUTPUT); pinMode(signalLow,OUTPUT); digitalWrite(signalLow,LOW); pinMode(redPin,OUTPUT); pinMode(greenPin,OUTPUT); pinMode(bluePin,OUTPUT); pinMode(spkrPin,OUTPUT); Serial.begin(9600); digitalWrite(ledPin,HIGH); pinMode(button,INPUT); digitalWrite(button,HIGH); } void loop() { checkSwitch(); if (mode){ value = analogRead(sensor); Serial.println(sensor); if (value >= 400) { color(255,255,0); // Yellow delay(1000); } else if (value >= 400) { color(255,0,0); // Red delay(1000); } else if (value >= 300) { color(0,255,255); // Cyan delay(1000); } else if (value >= 200){ color(0,255,0); // Green delay(1000); } else if (value >= 100) { color(0,0,255); // Blue delay(1000); } else if (value >= 0) { color(106,0,128); // Purple delay(1000); } else { color(255,255,255);// White delay(1000); } } else { color(0,0,0); // Turning off light xValue = analogRead(xPin); yValue = analogRead(yPin); zValue = analogRead(zPin); Serial.print(xValue); Serial.print("\t"); Serial.print(yValue); Serial.print("\t"); Serial.println(zValue); delay(100); if (xValue+yValue+zValue > 0){ int wavelength = xValue+yValue+zValue; digitalWrite(ledPin,HIGH); beep(spkrPin,wavelength,500); } } } /** * COPIED FROM LEAH BUECHLEY'S COLOR (RGB LEDS) EXAMPLE * http://web.media.mit.edu/~leah/LilyPad/06_rgb.html */ void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function { analogWrite(redPin, 255-red); analogWrite(bluePin, 255-blue); analogWrite(greenPin, 255-green); } /** * COPIED FROM LEAH BUECHLEY'S SOUND EXAMPLE * http://web.media.mit.edu/~leah/LilyPad/07_sound.html */ void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) // the sound producing function { int x; long delayAmount = (long)(1000000/frequencyInHertz); long loopTime = (long)((timeInMilliseconds*1000)/(delayAmount*2)); for (x=0;x