/* * Sequence Control * Copyright Sternlab 2006. * licenced under the Creative Commons Attribution 2.5 license * viewable at: http://creativecommons.org/licenses/by/2.5/ * contact[at]sternlab[dot]org * * This program animates images and uses an arduino-powered input device to control that animation. * More information about this project can be found at sternlab.org. */ int ledPin1 = 5; // LED connected to digital pin int ledPin2 = 6; int ledPin3 = 7; int ledPin4 = 8; int potPin = 5; // select the input pin for the potentiometer int val = 0; // variable to store the value coming from the sensor int value = 0; int lastval = 0; int pausePin = 2; int ffPin = 3; int revPin = 4; int currentPin; void setup() { pinMode(ledPin1, OUTPUT); // sets the digital pin as output pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); pinMode(ledPin4, OUTPUT); pinMode(pausePin, INPUT); pinMode(ffPin, INPUT); pinMode(revPin, INPUT); Serial.begin(9600); // use the serial port to send the values back to the computer } void flashLED(int whichPin, int duration){ digitalWrite(whichPin, HIGH); // sets the LED on delay(duration*2); // waits for a second digitalWrite(whichPin, LOW); // sets the LED off delay(duration/2); // waits for a second } void updateSpeed(){ value = analogRead(potPin); val = 1024 / value + 1; // read the value from the sensor if (val != lastval){ //Serial.print(" "); Serial.println(value); // print the value to the serial port //Serial.print(" "); lastval = val; } } void loop() { if ( digitalRead(pausePin) == 0) { Serial.print("P"); if (!digitalRead(ffPin)){ Serial.print('F'); currentPin++; if (currentPin > ledPin4){ currentPin = ledPin1; } flashLED(currentPin, val+20); delay(10); } else if (!digitalRead(revPin)) { Serial.print("R"); currentPin--; if (currentPin < ledPin1){ currentPin = ledPin4; } flashLED(currentPin, val+20); delay(10); } else { delay(10); } } else{ updateSpeed(); delay(val); flashLED(ledPin1, val); currentPin = ledPin1; updateSpeed(); flashLED(ledPin2, val); currentPin = ledPin2; updateSpeed(); flashLED(ledPin3, val); currentPin = ledPin3; updateSpeed(); flashLED(ledPin4, val); currentPin = ledPin4; } }