/* * trapdoor2018.ino * Ted Kinsman emkpph@rit.edu * Assistant Professor of Photographic Sciences * at Rochester Institute of Technology (RIT) * October 17, 2018 * This code opens a trap door and times a flash to photograph dropping scrabble letters. * The press of a pushbutton starts the action. */ const int flashPin = 3; // Set flash to pin 3 controls the opto-isolator const int LED = 4; //LED on pin 4 to tell that the system is running const int StartButton = 7; // Set push button to pin 7 this will be an input from a switch const int Door = 8; // Set valve to pin 8 connects to a reed switch which // controls the solenoid valve int buttonState = LOW; int DoorOpen = 95; // Set a delay variable for time (milliseconds) valve is open int DoorPause = 40; // set delay between drips (milliseconds) int flashDelay = 195; // Set a delay for flash to be triggered: adjust // this number to control how far the letters has fallen void setup() { pinMode(flashPin, OUTPUT); // Set pin 3 as an output pinMode(LED, OUTPUT); //LED on pin 4 is an output pinMode(StartButton, INPUT); // Set pin 7 as an input pinMode(Door, OUTPUT); // Set pin 8 as an output } void loop() { buttonState = digitalRead(StartButton); if (buttonState==HIGH) { //starts the drips if the button is pressed digitalWrite(LED, HIGH); //turns on the LED digitalWrite(Door, HIGH); // makes the door solenoid open delay(DoorPause); //keeps solenoid open for time (milliseconds) digitalWrite(Door, LOW); // turns off the solenoid delay(flashDelay); //wait the flash delay time to trigger flash digitalWrite(flashPin, HIGH); //trigger the flash delay(10); //keep flash trigger pin high long enough to trigger flash digitalWrite(flashPin, LOW); //turn off flash trigger delay(2000); // keeps the system in a pause mode to avoid false triggers digitalWrite(LED, LOW); } else{ digitalWrite(flashPin, LOW); //sets pins low digitalWrite(Door, LOW); //sets pins low } }