Skip to content

Instantly share code, notes, and snippets.

@smukkejohan
Created August 18, 2011 00:25
Show Gist options
  • Save smukkejohan/1153000 to your computer and use it in GitHub Desktop.
Save smukkejohan/1153000 to your computer and use it in GitHub Desktop.
The Architecture Run CPH 2011 - Arduino touch mp3trigger
// Johan Bichel Lindegaard 2011 http://johan.cc
// mp3trigger controller, 3 analog inputs controls 3 digital outputs
const int MP3TRIGGERPINS[] = {4,7,8}; // digital output pins for our
const int SENSORPINS[] = {A3,A4,A5};
const int THRESHOLDS[] = {100,100,100}; // threshold values to decide when the detected value is someone stepping on the sensor
const int TIMEOUTS[] = {1000,1000,1000}; // how long to wait for mp3triggers to finish playing their tracks
// these variables will change:
int sensorReadings[] = {0,0,0}; // variable to store the value read from the sensor pin
unsigned long lastPlayed[] = {0,0,0};
int i = 0;
void setup() {
for (i=0;i<3;i++) {
pinMode(MP3TRIGGERPINS[i], OUTPUT);
digitalWrite(MP3TRIGGERPINS[i], HIGH);
}
//Serial.begin(9600); // use the serial port
}
void loop() {
// read the sensors and store values in the array sensorReadings:
for (i=0;i<3;i++) {
sensorReadings[i] = analogRead(SENSORPINS[i]);
if ((millis() - lastPlayed[i]) > TIMEOUTS[i]) {
digitalWrite(MP3TRIGGERPINS[i], HIGH);
if (sensorReadings[i] >= THRESHOLDS[i]) {
lastPlayed[i] = millis();
digitalWrite(MP3TRIGGERPINS[i], LOW);
}
}
/*
Serial.print("sensor ");
Serial.print(i);
Serial.print(" reads ");
Serial.print(sensorReadings[i]);
Serial.println("-");
*/
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment