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;
}