Hey,
Im working on a solenoid orchestra. I am bringing MIDI from Ableton Live into Max, then sending serial messages to Arduino. running the code below. The problem occurs when solenoids are triggered by the midi. Instead of striking once but they strike repeatedly until a different MIDI signal is sent.
Any suggestions would be greatly appreciated. Ive been working on this for a while and con not figure it out. I have a feeling it has to do with the delays but Im not sure.
/*
/////////////////////////////////SOLENOID ORCHESTRA\\\\\\\\\\\\\\\\\
6 24Watt Solenoids controlled by external MIDI
2011 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 11
- Solenoid 5 to digital pin 12
- Solenoid 6 to digital pin 13
- 10K resistors to digital pins
*/
//---------------------------------VARS------------------------------------------
int serialvalue; // value for serial input
int SPins[] = {8, 9, 10, 11, 12 ,13};
//---------------------------------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(){
if(Serial.available()) // check to see if there's serial data in the buffer
{
serialvalue = Serial.read(); // read a byte of serial data
}
if (serialvalue == 60){
Serial.print(serialvalue); // echo the received serial value
solenoidStrike (11);
}
}
void solenoidStrike (int pinNumber) {
digitalWrite(pinNumber, HIGH); // set the LED on
delay(80); // wait for a second
digitalWrite(pinNumber, LOW); // set the LED off
delay(80); // wait for a second
}