//Sensor Inputs by nick lally: http://nicklally.com //with help from: //Accelerometer Sensor: Matt @ http://antipastohw.blogspot.com/: Author of original code base: Marcos Yarza, Malmo University - Sweden, http://www.0j0.org //Pin definitions int ledPin = 13; int xaccPin = 7; int yaccPin = 6; int photoPin = 0; int piezoPin = 1; int speakerPin = 3; int vibratePin = 10; //Global variables long xacc = 0; long yacc = 0; int valPhoto = 0; int valPiezo = 0; boolean DEBUG = true; void setup() { beginSerial(9600); // Sets the baud rate to 9600 pinMode(ledPin, OUTPUT); pinMode(xaccPin, INPUT); pinMode(yaccPin, INPUT); pinMode(speakerPin, OUTPUT); pinMode(vibratePin, OUTPUT); //clear the initial pin readouts pinMode(2, OUTPUT);pinMode(3, OUTPUT);pinMode(4, OUTPUT);pinMode(5, OUTPUT); digitalWrite(2, LOW);digitalWrite(3, LOW);digitalWrite(4, LOW);digitalWrite(5, LOW); } long readAcceleration(int axe){ int count = 0; long accel = 0; int value = 0; value = digitalRead(axe); while(value == HIGH) { // Loop until pin reads a low value = digitalRead(axe); } while(value == LOW) { // Loop until pin reads a high value = digitalRead(axe); } while(value == HIGH) { // Loop until pin reads a low and count value = digitalRead(axe); count = count + 1; } //accel = abs(8 * (count * 18 / 10 - 500)); //this was the original function accel = count; return accel; } void loop() { //Grab the accelerometer readings: xacc = readAcceleration(xaccPin); //reads and represents acceleration X yacc = readAcceleration(yaccPin); //reads and represents acceleration Y //Grab photocell reading valPhoto = analogRead(photoPin); //Grab mic reading valPiezo = analogRead(piezoPin); //Write to Speaker for (int i=0; i 10) { for (int i=0; i<5000; i++){ digitalWrite(speakerPin, HIGH); delayMicroseconds(500); digitalWrite(speakerPin, LOW); delayMicroseconds(500); } } //Vibrate analogWrite(vibratePin, map(valPhoto, 0, 1000, 0, 255)); //Print the output to the serial port: if (DEBUG == true){ Serial.print("X:"); Serial.print(xacc); Serial.print(" Y:"); Serial.print(yacc); Serial.print(" LIGHT:"); Serial.print(valPhoto); Serial.print(" PIEZO:"); Serial.print(valPiezo); Serial.print("\n\r"); delay(100); } }