Pages: [1]   Go Down
Author Topic: help with function  (Read 307 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi.I want to make KNIGHT RIDER.i write LedOff() function to turn off leds.it work well.but i cant write LedsOn() function please help me.I want something like this
 LedsOn(2);  led 2 turns on
LedsOn(2,3); led 2 and led 3 turns on
LedsOn(2,3,4,5,6,7);  led 2,3,4,5,6,7 turns on

this code work fine
Code:
int pinArray[] = {6, 10, 13,};

void setup(){
  for (int count=0;count<3;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
}

void loop() {
  digitalWrite(6, HIGH);
  delay(1000);
  LedsOff();
 
  digitalWrite(6, HIGH);
  digitalWrite(10, HIGH);
  delay(1000);
  LedsOff();
 
  digitalWrite(6, HIGH);
  digitalWrite(10, HIGH);
  digitalWrite(13, HIGH);
  delay(1000);
  LedsOff();
 
  digitalWrite(13, HIGH);
  delay(1000);
  LedsOff();
 
  digitalWrite(10, HIGH);
  delay(1000);
  LedsOff();
 
  digitalWrite(6, HIGH);
  delay(1000);
  LedsOff();
 
}

void LedsOff(void)
{
  for (int count=0;count<3;count++) {
    digitalWrite(pinArray[count], LOW);
  }
}

but in this code i get error   INVALID CONVERSION FROM 'INT' to 'int*'
Code:
int pinArray[] = {6, 10, 13,};

void setup(){
  for (int count=0;count<3;count++) {
    pinMode(pinArray[count], OUTPUT);
  }
}

void loop() {
 
  LedsOn(6);
  delay(1000);
  LedsOff();
 
  LedsOn(6,10);
  delay(1000);
  LedsOff();
 
  LedsOn(6,10,13);
  delay(1000);
  LedsOff();
 
}

void LedsOff(void)
{
  for (int count=0;count<3;count++) {
    digitalWrite(pinArray[count], LOW);
  }
}

void LedsOn(int pinAray[3])
{
  for (int counts=0;counts<3;counts++) {
    digitalWrite(pinAray[counts], HIGH);
  }
}
Logged

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

Code:
digitalWrite(pinAray[counts], HIGH);
spelling?
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.

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

I dont understand what you say.can you write correct function.thanks
Logged

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

Array != Aray
I don't understand why you pass one function an array pointer, but not to the other.
Code:
LedsOn(6,10,13);
There are no function overloads visible. Did you post all your code?
« Last Edit: March 03, 2013, 01:45:50 pm by AWOL » 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.

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

my LedsOn function is

Code:
void LedsOn(int pinAray[3])
{
  for (int counts=0;counts<3;counts++) {
    digitalWrite(pinAray[counts], HIGH);
  }
}
« Last Edit: March 03, 2013, 01:51:50 pm by farsajik » Logged

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

Code:
LedsOn(6,10,13);
so why call it like that, if there's no overload?
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.

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

please write correct form .how it should be???
Logged

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

Quote
how it should be?
I don't know - I don't understand the form of the call you're using.
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.

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void LedsOn(int pinAray[3])

What you're saying here is When I call you, I'm going to send you an array of ints, which will be represented by the address of the first element.

Code:
LedsOn(6,10,13);

But when you call it, you're saying Here are three, independent int variables for you to use.

You need to package the values you want to send in an array, and send the array as the argument. Since it looks like you aren't going to be only sending three values, I would also pass it the number of pins you are sending it.
Logged

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

how solve this problem?
Logged

California
Offline Offline
Faraday Member
**
Karma: 82
Posts: 3123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

how solve this problem?

By doing what I said, pack the pins in an array and send it to the function.
Logged

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

.and if the array is shorter than the function expects, don't forget to send the length.
Or use a bit mask.
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.

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

i am new in arduino programming.can you show me some example how do it.thanks for anwering
Logged

Pages: [1]   Go Up
Jump to: