Go Down

Topic: 2 pins at the same time (Read 624 times) previous topic - next topic

Tegra

So i got this program and it works fine. It is supposed to generate a pwm signal of a predetermined frequency by using a function.
The downside however is that i can only run this function on one pin at a time. How can i get it to start and finish on 2 pins simultaneously (for example pin 10 and 11)?
For my project i need 4 pins to run in pairs (with delays between the pairs)



Code: [Select]
void frecventa(byte targetPin, int highRate, int lowRate, int n)
/* targetPin=nr of pin used
   highRate=High state duration
   lowRate=Low state duration
   n=number of repeats*/
{
   
    for (int i=0; i < n; i++)
    {
    digitalWrite(targetPin, HIGH);   
    delay(highRate);                     
    digitalWrite(targetPin, LOW);   
    delay(lowRate);
  }
}

void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
}

void loop() {
frecventa(9,16,16,70);
delay(2000);
frecventa(10,16,16,70);
delay(2000);
}

AWOL

Have you looked at the blink without delay example?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

MarkT

Have you though about passing an array of pin numbers instead of a single pin number to the function?
[ I won't respond to messages, use the forum please ]

Tegra


Have you though about passing an array of pin numbers instead of a single pin number to the function?

how do i do that, can i get an example?

AWOL

Any function that takes an array or pointer as an argument should give you a clue.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy