Pages: [1] 2   Go Down
Author Topic: to many arguments to function  (Read 790 times)
0 Members and 1 Guest are viewing this topic.
Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all! I was writing some Arduino seven seg code, and it wouldn't compile, even though there was nothing wrong with the code.
Code:
void sevenseg(int val){
  switch(val){
    case'0': zero();
    break;
    case'1': one();
    break;
    case'2': two();
    break;
    case'3': three();
    break;
    case'4': four();
    break;
    case'5': five();
    break;
    case'6': six();
    break;
    case'7': seven();
    break;
    case'8': eight();
    break;
    case'9': nine();
    break;
  }
}
the error message:
Quote
/sevenseg.h: In function 'void setup()':
sevenseg.h:262: error: too many arguments to function 'void sevenseg(int)'
sketch_jan29a:13: error: at this point in file
Can anyone please tell me what the problem is?
Thanks
Habib
Logged

What is man's best friend? The breadboard!

Seattle, WA USA
Online Online
Brattain Member
*****
Karma: 549
Posts: 46084
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Can anyone please tell me what the problem is?
Sure. The function expects one argument. You are calling it with more than one. Don't do that.
Logged

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

Quote
Can anyone please tell me what the problem is?
The problem is you didn't show us the code (there's a big clue here - "In function 'void setup()': ")
And what PaulS said.
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.

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

All right, this is the full code:
Code:
#include"sevenseg.h"
int val=0;
void setup(){
  sevensegpins(13, 12, 11, 10, 9, 8, 7);
  common_cathode(true);
}
void loop(){
  val=(analogRead(0));
  val=map(val, 0, 1023, 0, 9);
  sevenseg(val);
}
and also
Code:
#include<Arduino.h>
int pin_a;
int pin_b;
int pin_c;
int pin_d;
int pin_e;
int pin_f;
int pin_g;
int ON;
int OFF;
void sevensegpins(int a, int b, int c, int d, int e, int f, int g){
  pin_a=a;
  pin_b=b;
  pin_c=c;
  pin_d=d;
  pin_e=e;
  pin_f=f;
  pin_g=g;
  pinMode(pin_a, OUTPUT);
  pinMode(pin_b, OUTPUT);
  pinMode(pin_c, OUTPUT);
  pinMode(pin_d, OUTPUT);
  pinMode(pin_e, OUTPUT);
  pinMode(pin_f, OUTPUT);
  pinMode(pin_g, OUTPUT);
}
void common_cathode(boolean cathode){
  if(cathode==true){
    ON=HIGH;
    OFF=LOW;
  }
  else{
    ON=LOW;
    OFF=HIGH;
  }
}
void clearall(){
  digitalWrite(pin_a, OFF);
  digitalWrite(pin_b, OFF);
  digitalWrite(pin_c, OFF);
  digitalWrite(pin_d, OFF);
  digitalWrite(pin_e, OFF);
  digitalWrite(pin_f, OFF);
  digitalWrite(pin_g, OFF);
}
void zero(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void one(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void two(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_d, ON);
}
void three(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void four(){
  clearall();
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void five(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void six(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void seven(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
}
void eight(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void nine(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void lettera(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterb(){
  clearall();
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_g, ON);
}
void letterB(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterc(){
  clearall();
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_g, ON);
}
void letterC(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void letterd(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_g, ON);
}
void letterD(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void lettere(){
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterE(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterf(){ 
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_g, ON);
  }
void letterh(){
  clearall();
  digitalWrite(pin_c, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterH(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void letterl(){
  clearall();
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void letterL(){
  clearall();
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_d, ON);
}
void letterp(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letterq(){
  digitalWrite(pin_a, ON);
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
}
void letters(){
  clearall();
  digitalWrite(pin_a, ON);
  digitalWrite(pin_f, ON);
  digitalWrite(pin_g, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
}
void letteru(){
  clearall();
  digitalWrite(pin_b, ON);
  digitalWrite(pin_c, ON);
  digitalWrite(pin_d, ON);
  digitalWrite(pin_e, ON);
  digitalWrite(pin_f, ON);
}
void sevenseg(int val){
  switch(val){
    case'0': zero();
    break;
    case'1': one();
    break;
    case'2': two();
    break;
    case'3': three();
    break;
    case'4': four();
    break;
    case'5': five();
    break;
    case'6': six();
    break;
    case'7': seven();
    break;
    case'8': eight();
    break;
    case'9': nine();
    break;
  }
}
Logged

What is man's best friend? The breadboard!

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

PS it used to compile
Logged

What is man's best friend? The breadboard!

0
Offline Offline
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know if this is your bug or not, but attempting to reassign a system-provided define like ON or OFF like this is creative but not going to work:
Code:
void common_cathode(boolean cathode){
  if(cathode==true){
    ON=HIGH;
    OFF=LOW;
  }
  else{
    ON=LOW;
    OFF=HIGH;
  }
}

-br

Edit: Never mind.  I was mistaken in assuming the ON and OFF were system defines.  My bad.
« Last Edit: January 29, 2013, 10:14:21 am by billroy » Logged

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

I'd suggest the code you posted is not the code you're trying to compile.
Here's the error message I got:
Quote
Binary sketch size: 2436 bytes (of a 14336 byte maximum)

(compiled for 168 on IDE 1.0)
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.

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

Quote
but attempting to reassign a system-provided define like ON or OFF like this is creative but not going to work:
Why not?
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
God Member
*****
Karma: 39
Posts: 986
Get Bitlash: http://bitlash.net
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I had myself confused that ON was a #define.  More coffee...

-br
Logged

Queens, New York
Offline Offline
Faraday Member
**
Karma: 65
Posts: 2929
"Of all the things I've ever lost, I miss my mind the most" -Ozzy Osbourne
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You dont need to have,
Quote
digitalWrite(pin_a, OFF);
  digitalWrite(pin_b, OFF);
  digitalWrite(pin_c, OFF);
  digitalWrite(pin_d, OFF);
  digitalWrite(pin_e, OFF);
  digitalWrite(pin_f, OFF);
  digitalWrite(pin_g, OFF);
there is an easier way to get your LEDs to light up, but if it compiles like that and thats what you want to use, then go for it.

Alternative:
just use an array,
0b00000000 = all off
0b00101010  = something on
0b00010101 = something else on
.
.
0b11111111 = all on
Logged

Created Libraries:
NPV2 (NewPasswordV2),  TFT_Extension, OneWireKeypad, SerialServo.
Will provide libraries if asked in PM or forum.

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey all this code compiled in IDE 1.0 but did not compile in Arduino ERW. I was using ERW...Sorry for the time.
Logged

What is man's best friend? The breadboard!

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@HazerdousMind Thank you I knew that but this was old code I was going through, copy and pasting it
Thanks anyway!
Habib
Logged

What is man's best friend? The breadboard!

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

Code:
val=map(val, 0, 1023, 0, 9);
  sevenseg(val);

Code:
void sevenseg(int val){
  switch(val){
    case'0': zero();
    break;
    case'1': one();
    break;
    case'2': two();

Your code will not work - lose the quotes.
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.

Beijing
Offline Offline
Full Member
***
Karma: 3
Posts: 193
Skype name habib.derbyshire
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I know... But why not? It used to.
Logged

What is man's best friend? The breadboard!

Offline Offline
Edison Member
*
Karma: 18
Posts: 1170
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

'0' is ASCII character 0, not the integer 0. ASCII character 0 is actually decimal 48.
Logged

Pages: [1] 2   Go Up
Jump to: