hello. i'm thinking about building a trigger that fires off a sequence of pneumatic 12V solenoids valves (LEDs at this point) and a high-speed flash for some photography work. I've purchased one of these: http://arduino-direct.com/sunshop/index.php?l=product_detail&p=155 and am slowly making progress on the code. fyi, my skill level is still pretty basic.
the first code i wrote worked great, but included delays which made it tricky to control the simultaneous opening 2 "valves". i dug around the forum and found a bit of code that doesn't use delay and is what this is based on.
/// code based on http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1288016644/15#15
const int relay1Pin = 12; // the number of the Relay pins
const int relay2Pin = 11;
const int relay3Pin = 10;
const int relay4Pin = 9;
const int flashPin = 8; // opto-isolator anode connected to digital pin 8
const int buttonPin = 2;
int flashState = LOW;
int globalReset = 4000;
unsigned long btnMillis = 0; //clock value to be stored at the time milli() is called
void setup()
{
pinMode(relay1Pin, OUTPUT); // initialize the Relay pins as an output:
pinMode(relay2Pin, OUTPUT);
pinMode(relay3Pin, OUTPUT);
pinMode(relay4Pin, OUTPUT);
pinMode(flashPin, OUTPUT); // declare flashPin as as OUTPUT
attachInterrupt(0, btnDown, RISING); //0 = digital pin 2 or 1 = digital pin 3
}
void loop()
{
if (btnMillis != 0)
{
unsigned long timePassed = millis() - btnMillis;
int relay1Delay = 1000;
int relay1Duration = 1500;
int relay2Delay = 1250;
int relay2Duration = 1500;
int relay3Delay = 1450;
int relay3Duration = 1600;
int relay4Delay = 1550;
int relay4Duration = 1700;
int flash1Delay = 1500;
int flash1Duration = 20;
int relay1Timer = relay1Delay+relay1Duration;
int relay2Timer = relay2Delay+relay2Duration;
int relay3Timer = relay3Delay+relay3Duration;
int relay4Timer = relay4Delay+relay4Duration;
int flash1Timer = flash1Delay+flash1Duration;
//Flash
if (timePassed >= flash1Delay && timePassed <= flash1Delay)
{
flashState = HIGH;
digitalWrite(flashPin, flashState); // trigger flash by bringing digital output to high
}
if (timePassed >= flash1Timer && timePassed <= flash1Timer)
{
flashState = LOW;
digitalWrite(flashPin, flashState); // set it back to low
}
//Relay 1
if (timePassed >= relay1Delay && timePassed <= relay1Delay+50)
{
digitalWrite(relay1Pin, HIGH); //turn on Relay 1 pin
}
if (timePassed >= relay1Timer && timePassed <= relay1Timer+50)
{
digitalWrite(relay1Pin, LOW); //turn off Relay 1 pin
}
//Relay 2
if (timePassed >= relay2Delay && timePassed <= relay2Delay)
{
digitalWrite(relay2Pin, HIGH); //turn on Relay 2 pin
}
if (timePassed >= relay2Timer && timePassed <= relay2Timer)
{
digitalWrite(relay2Pin, LOW); //turn off Relay 2 pin
}
//Relay 3
if (timePassed >= relay3Delay && timePassed <= relay3Delay)
{
digitalWrite(relay3Pin, HIGH); //turn on Relay 3 pin
}
if (timePassed >= relay3Timer && timePassed <= relay3Timer)
{
digitalWrite(relay3Pin, LOW); //turn off Relay 3 pin
}
//Relay 4
if (timePassed >= relay4Delay && timePassed <= relay4Delay)
{
digitalWrite(relay4Pin, HIGH); //turn on Relay 4 pin
}
if (timePassed >= relay4Timer && timePassed <= relay4Timer)
{
digitalWrite(relay4Pin, LOW); //turn off Relay 4 pin
}
//Longest off time, to re-enable the button
if (timePassed >= globalReset)
{
btnMillis = 0;
}
}
}
void btnDown()
{
if (btnMillis != 0) return;
btnMillis = millis();
}
the problem i'm having, is that it's erratically not turning on/off a light or popping off the strobe. wondering if this has anything to do with the button not being bounced? still trying to figure that one out with the attachInterrupt.
would be grateful if someone could see what's being overlooked or has any suggestions.
thanks!