Solenoids without delay

Hey,

Im trying to strike a solenoid for 80 ms after it is triggered by externaly (midi). I been trying to adapt the blink without delay example but can't get it right. The rough code is below. Can someone please walk me through the logic on this one. Thanks.
/*

//////////////////////////////SOLENOID ORCHESTRA\\\\\\\\\\\\\\\\\

6 24Watt Solenoids controlSolenoid by external MIDI
205 Michael Manning

The circuit:

  • Solenoid 1 to digital pin 8
  • Solenoid 2 to digital pin 9
  • Solenoid 3 to digital pin 10
  • Solenoid 4 to digital pin 5
  • Solenoid 5 to digital pin 12
  • Solenoid 6 to digital pin 13
  • 10K resistors to digital pins

*/

//---------------------------------VARS------------------------------------------

long strikeTime = 0;

int serialvalue; // value for serial input

int SPins[] = {8, 9, 10, 5, 12 ,13}; //pin array

int state = LOW; // SolenoidState used to set the Solenoid

long currentMillis = 0; // will store last time Solenoid was updated

long interval = 80; // interval at which to blink (milliseconds)

//---------------------------------SETUP------------------------------------------

void setup(){

for (int thisS = 0; thisS < 6; thisS++) { // initialize pins
pinMode(SPins[thisS], OUTPUT);

}
Serial.begin(9600); // open the arduino serial port
}

//---------------------------------LOOP------------------------------------------

void loop(){

currentTime = millis();

if (currentTime - strikeTime > interval){
solenoidStrike (5, LOW);
}

if(Serial.available()) // check to see if there's serial data in the buffer
{
serialvalue = Serial.read(); // read a byte of serial data
Serial.print(serialvalue);

}
if (serialvalue == 60){
Serial.print(serialvalue); // echo the received serial valu
solenoidStrike (5, HIGH);
}
}

void solenoidStrike (int pinNumber, int state) {
digitalWrite(pinNumber, state); // set the Solenoid on
long strikeTime = millis();
}

// HELP!!

}

serialvalue = 0;
}

serialvalue = 0;
}

void solenoidStrike (int pinNumber, int state) {
    digitalWrite(pinNumber, state);   // set the Solenoid on
    long strikeTime = millis(); 
  }

"strikeTime" is local to this function - it can't be seen to any other function in the sketch.
Try putting it at global scope, above "setup"

EDIT: You already have a global scope "strikeTime", just lose the "long" off the front of the declaration in "solenoidStrike"

Please clean up your code and use -button to mark it as such.

One thing that might cause you a problem is this part:

  void solenoidStrike (int pinNumber, int state) {

digitalWrite(pinNumber, state);   // set the Solenoid on
   long strikeTime = millis();
 }

Most likely the long is wrong and it should be:

  void solenoidStrike (int pinNumber, int state) {
    digitalWrite(pinNumber, state);   // set the Solenoid on
    strikeTime = millis();
  }

Other than this, it would be very helpful if you let us know, what the program does and in what way you think it fails. If it doesn't compile, read the error messages and clean that up first.

Korman

if (serialvalue == 60){
     Serial.print(serialvalue); // echo the received serial valu
     solenoidStrike (5, HIGH);
   }

If timing is critical, it may be better to put the "solenoidStrike" before the print.
At 9600 bps, each character takes over 1ms to print, and is blocking until the last character is written to the transmit buffer.

This program is to control 6 solenoids. Each time the serial reads an integer from max/msp between 60 and 66 it strikes the corresponding solenoid. The problem I am having is triggering each solenoid for 80ms without a delay so that the program doesn't miss any serial data coming in.

I am also needing to find a way that allows for two or more solenoids to be triggered at the exact same time. Right now the code only handles one serial read integer and one solenoid a loop. I know void loop is fast but timing is critical as it is a musical thing.

If anyone has examples that I could learn from it would be greatly appreciated.

thanks for the posts BTW

cheers

Have you corrected the scope problem I pointed out above?