int pulseWidth = variable/different for all pwm channels

Hello
I’m bit of a noob here but I’am working on a project were I would like to define the 'int pulseWidth = ’
per pwm channel.
Is this even possible?
In the code below you can see its’s all the same for all channels.
Maybe someone can show me how 2 or 3 changeable channels of code looks like and I can copy paste them :wink: Thnx so much
Kind regards
William

unsigned long time;
unsigned long timeInArray[8];
int pulseWidth = 80;

#include <Servo.h>

void setup() {
// initialize both serial ports:
Serial.begin(9600);

pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}

void loop() {
// read from port 1

unsigned long currentMillis = millis(); // huidige tijd in currentMillis

if (Serial.available()) {
int inByte = Serial.read();

for (int x = 1; x < 10; x++) {
if (inByte == x+34) { // MIDI noot 36 t/m 43
digitalWrite(x, HIGH); // stuurt HIGH naar Arduino pin 2 t/m 9
}

for (int x = 1; x < 10; x++) {
if (inByte == x+34) { // stop in de array het huidige tijdstip als er een note is
timeInArray[x-2] = currentMillis;
}
}
}
}

for (int x = 1; x < 10; x++) { if (timeInArray[x-2] != 0) {
if ( currentMillis - timeInArray[x-2] >= pulseWidth ) {
timeInArray[x-2] = 0; digitalWrite(x, LOW);
}
}
}

}

Why do you want different pulse widths?

thnx for your reply
long story short: to control pneumatic cilinders with midi.
It works well already but different cilinders need different pulse width
Somebody told me that I have to change my set up to Firmata
but that takes some while for me to figure out and with this i’am almost there :wink:
Is it complex?

It works well already but different cilinders need different pulse width

You need to talk more about the hardware you are using. I suspect that you have something between the Arduino and the cylinder, like a motor shield. Unless you are using several different kinds of shields, you don't need different pulse widths. You need different duty cycles.

thnx for your reply
yes. 24v magnetic valves (festo, 5/2 way)
breadbord with tip 120, diode 1004 and 1k resistor (from google images: arduino solenoid).
bit overdone for the 24v valves but I also use 12v solenoids that create quit a peak.
It works perfect and steady so far. Signals come from Ableton with a Open Frameworks patch midi to arduino.
If I change the pulse width in the arduino code I can tune the air inlet for the cilinders (and thus the punch ;). But for the solenoids and the different valves/cilinders I need different pulse widths for sure.
In the end I would like the lengt of a midi note creating pulse width but thats a different ball game.. for me at least.