You can use the millis()
function to see how much time has passed and use this to create your waveform while still being able to perform other tasks. You will check in which part of the wave you are in each iteration of loop()
and adjust your outputs accordingly.
E.g:
long vhtime;
uint8_t vhpin = 9; // the VH output pin
uint8_t vcpin = 10; // the VC output pin
long period = 250; // the period of your pwm signal in ms
long vhduty = 14; // amount of ms vh should be high
long vcdelay = 2; // amount of ms we wait for vc to go high after vh has gone high
long vcduty = 5; // amount of ms vc should be high
long curtime; // this will hold our current position in one period of the waveform
void setup() {
pinMode(vhpin, OUT);
pinMode(vcpin, OUT);
digitalWrite(vcpin, LOW);
digitalWrite(vhpin, HIGH);
vhtime = millis();
}
void loop() {
curtime = millis() - vhtime;
if (curtime > vhduty) // we are in the last 236ms of the wave, vh should be low
digitalWrite(vhpin, LOW);
else // we are in the first 14ms of the wave, vh should be high
digitalWrite(vhpin, HIGH);
if (curtime > vcdelay && curtime < vcduty + vcdelay) // vc should be high during this time
digitalWrite(vcpin, HIGH);
else
digitalWrite(vcpin, LOW);
if (curtime > period) {
// we should start a new period
digitalWrite(vhpin, HIGH);
vhtime = millis();
}
// do your other calculations here
}