Pages: [1]   Go Down
Author Topic: 2 pins at the same time  (Read 517 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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);
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you looked at the blink without delay example?
Logged

"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.

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12048
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 299
Posts: 26196
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Any function that takes an array or pointer as an argument should give you a clue.
Logged

"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.

Pages: [1]   Go Up
Jump to: