I found a couple of solenoids in my office and decided to use them for this week's assignment. Initially, I was using Firmata to hook Arduino up to Max MSP with Maxuino and control the speed of the solenoids simply using faders on a MIDI controller through USB. Maxuino was not responding, so I decided to get two potentiometers from the lab instead and take the opportunity to read an analog signal from the Arduino using two of the analog pins.
This worked, but the limitation right now is that the values sent to each solenoid from the digital pins only update once the loop finishes, whereas Maxuino would have allowed for independent control of each solenoid in real time.
Here is the arduino code:
const int potPin1 = A0;
const int potPin2 = A1;
int solenoidPin1 = 12;
int solenoidPin2 = 13;
int value1;
int value2;
void setup() {
pinMode(solenoidPin1, OUTPUT);
pinMode(solenoidPin2, OUTPUT);
pinMode(potPin1, INPUT);
pinMode(potPin2, INPUT);
}
void loop() {
value1 = analogRead(potPin1);
value1 = map(value1, 0, 1023, 10, 500);
value2 = analogRead(potPin2);
value2 = map(value2, 0, 1023, 10, 500);
digitalWrite(solenoidPin1, HIGH); //Switch Solenoid ON
delay(value1); //Wait x milliseconds
digitalWrite(solenoidPin1, LOW); //Switch Solenoid OFF
delay(value1 + 10); //Wait x milliseconds
digitalWrite(solenoidPin2, HIGH);
delay(value2);
digitalWrite(solenoidPin2, LOW);
delay(value2 + 10);
}
I used this scheme for the solenoids, except the one I have have are rated of 4.5V each and one 9V battery was enough to power both.
I ran into some trouble when I tried to use more than two solenoids, even if I tried adding another battery. Hopefully I will be able to use multiple solenoids in the future.
I had initially planned to